Load Texture at Run time from file

Hi,

The below code will load a texture from the resources - how would i load C: est ex.png ?

function Start () {
  var go = new GameObject.CreatePrimitive(PrimitiveType.Plane); 
  go.renderer.material.mainTexture = Resources.Load("glass");
}

There does not seem to be a load method accepting system paths :( [can i cheat this with mono?]

David

Use the WWW class, and provide a file url in the form of:

var url = "file://C:/test/tex.png";

You can then read out the www.texture value once the www request has completed. For example:

function Start () {
     // Start a download of the given URL
    var www : WWW = new WWW (url);

    // Wait for download to complete
    yield www;

    // assign texture
    renderer.material.mainTexture = www.texture; 
}

This should work in standalone builds, but won't work for webplayer builds.

If you're using C#, see this answer for more information on how to use WWW in c#.

I believe you use persistentDataPath after extacting the data into it at runtime:

function Start () {
   // Start a download of the given URL
  var www : WWW = new WWW (Application.persistentDataPath + "filepathinPersistentData");
 // Wait for download to complete
 yield www;
 // assign texture
 renderer.material.mainTexture = www.texture; 
}

That will work on android, might work on webgl depending on permissions, not sure about that one.