My issue is quite simple, but annoying. I am loading my resources wrong, but I don’t know what I am doing wrong (first time loading dynamically from a resource folder).
So this is what my code looks like:
Item cItem = new Item(int.Parse(id),name,descr,
Resources.Load("ItemSprites/"+tex) as Texture);
Obviously everything is very arbitrary with this little snippet, but tex is a string for the texture’s name and ItemSprites is the folder withing my Resources folder.
PIC:
I know for sure that tex is correct because I am printing it out right that line of code.
When I am trying to draw my texture I get this:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUI.DrawTexture (Rect position, UnityEngine.Texture image, ScaleMode scaleMode, Boolean alphaBlend, Single imageAspect) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/GUI.cs:157)
UnityEngine.GUI.DrawTexture (Rect position, UnityEngine.Texture image) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/GUI.cs:152)
UIManager.OnGUI () (at Assets/Scripts/UIManager.cs:307)
Here is the drawing code:
int _i = 0;
foreach(KeyValuePair<int, Item> item in InventoryManager.Items)
{
GUI.DrawTexture(new Rect(90*_i,0,60,60),item.Value.tex);
_i++;
}
Obviously its not yelling at me for my Item being null since I am looping through my dictionary, which means my texture must be null. So that means I am loading the resource wrong! What am I doing wrong?
Thanks in advanced!