- Home /
Load images (textures)
Could someone explain me why this works:
const string texture = "Assets/Resources/Question/";
for(int i = 0; i < toggleTxt.Length; i++){
inputTexture[i] = (Texture2D)Resources.LoadAssetAtPath(texture+answers[i],typeof(Texture2D));
}
and this one don't
const string texture1 = "Assets/ZWORD/Question/pictures/";
for(int i = 0; i < toggleTxt.Length; i++){
inputTexture[i] = (Texture2D)Resources.Load(texture+answers[i]) as Texture2D;
}
but Debug.Log(texture+answers[i]); shows me name correctly: Assets/ZWORD/Question/pictures/lelija.jpg
Answer by karljj1 · Apr 14, 2015 at 05:08 PM
The file needs to be stored in a "Resources" directory.
ok i understand it. But it don't work when i build it for web player.The file needs to be stored in a "Resources" directory.
From the documentation:
The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted.
http://docs.unity3d.com/ScriptReference/Resources.Load.html That works for web-player too.
const string texture = "Assets/Resources/Question/";
inputTexture[i] = (Texture2D)Resources.Load(texture+answers[i]) as Texture2D;
still can't understand why i get NULL values at this line:
inputTexture[i] = (Texture2D)Resources.Load(texture+answers[i], typeof(Texture2D))
You do not need the full path. Resources looks inside the Resources folder and down the path you provide so in your case you ask:
"Resources/" + "Assets/Resources/Question/";
And since Assets is not there, you get null.
Remove Assets/Resources.
Your answer
Follow this Question
Related Questions
Random picture picker 1 Answer
Is there a way to analyse pictures in Unity? 1 Answer
facebook profile pic not working 0 Answers
Download pictures and store them temporarily 1 Answer
Taking screenshots on iOS 0 Answers