Search Unity

Attaching Texture2D on the fly!

Discussion in 'Scripting' started by giancamati, Dec 2, 2010.

  1. giancamati

    giancamati

    Joined:
    Aug 4, 2010
    Posts:
    518
    Hello everybody,

    I have a 3D Model which is uploaded in my scene at Runtime. Its format is .OBJ with no materials. Now, I have the path to the texture I'd like to attach. So, I created a script which is attached as a component to the 3D Model. and this is the script. I can't see any texture2D attached so... i wonder if that is a problem because I work with UNITY3D Free version.

    var filename: String = "file:///C:/Program%20Files/wamp/www/OBJs/Rooms/Petrie/wall_texture_4012148.JPG";

    function Start() {
    var www: WWW = new WWW(filename);

    yield www;

    renderer.material.mainTexture = www.texture;

    }