- Home /
Question by
Barsby · May 20, 2014 at 10:25 PM ·
c#guiguitexturegui.drawtexture
Load a sprite as a texture from.
This works
public Texture testTexture;
void OnGUI() {
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), testTexture);
}
I can drag and drop a texture, that works fine.
However I am trying to make it more dynamic.
So, I have a folder called resources, with a selection of PNG files (1.png, 2.png, 3.png...) I have set to sprites. The following does not work.
Texture img = Resources.Load("1.png") as Texture;
if (img) {
GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height), productTexture);
}
else {
Debug.Log("Something bad happened, but I was prepared for that");
}
Suggestions?
Comment
Why don't you simply use a List or an array? It seems easier and you will get inspector support
Best Answer
Answer by Xumbu · May 20, 2014 at 10:35 PM
don't use file ending to load from resources.
try Resources.Load("1")
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
GUI.DrawTexture() into a Layer? 1 Answer
Gui Texture Differences 1 Answer
ASPECT RATIO FILTER IN OnGUI? 3 Answers
Toggle GuiTexture 1 Answer