Hi
Anybody tell me what is wrong with this code please?
var bannerFile = "/banner01.jpg";
private var bannerPath = "";
bannerPath = Application.dataPath + bannerFile;
function Start(){
var www : WWW = new WWW (bannerPath);
yield www;
gameObject.renderer.material.mainTexture = www.texture;
}
I have confirmed that banner01.jpg is in the exe path and works fine if used manually.
This is a standalone windows exe build
The banner texture always comes up as a red questionmark which I assume is not found.
I have output the result of bannerPath and it does indeed point to the file
Cheers for any help.
Anim
After much hair pulling I decided to hard-code the path which works fine.
Shouldn’t you use \ instead of /, for stand alone ?
Just my little share, and my little thoughts
Cenda
October 5, 2010, 10:25am
4
I had same problem. In Unity 3 “Application.dataPath” have to be in function so you need move it to Start or Awake function When you read error message it will be there.
The issue is that the WWW class uses a different protocol.
Application.dataPath returns C:/… or /… whereas WWW looks for either file:/ or http:/ for it’s beginning extensions.
To convert a path to something WWW can use I use:
string file = Application.dataPath + filePath;
//Catch for Windows path formatting
if(file[0] != '/')
{
//Windows style
file = "file" + file.Substring(1);
}
else
{
Mac Style
file = "file:" + file;
}
WWW import = new WWW(file);
Edit: Using file is for accessing local resources.