WWW Class problem!!!

I want to use WWW Class load a local texture as spotlight cookie. But,this texture cann’t display.

Why???help10118-1.png

var www : WWW ;
var Lcookie : Texture2D ;

function Start () {
   www = new WWW ("file://"+Application.dataPath+"/Standard Assets/Light Cookies/1.jpg");
   yield www;
   Lcookie = www.texture ;
}

function LateUpdate () {
   light.cookie = Lcookie ;
}

1 Answer

1

Ok:

  • the file protocol also expects a hostname. If you want to refer to a local file, use file:///path/file
  • Application.dataPath will return the project folder but only in the editor. The project folder isn’t available at runtime. All assets get packed into resource-packages which are built into your final application.
  • The usual way to reference an asset is to simply drag the texture onto your Lcookie variable of your script in the inspector.
  • If you want to load it dynamically you could place the texture into a Resources folder and use Resources.Load. See this page for more details.