- Home /
Question by
Villlgaer · Oct 15, 2014 at 03:19 PM ·
errorgraphicstexture2ddrawtexture
Unity3D texture2d error help
please help this error shoes up every time: "DrawGUITexture: texture is null UnityEngine.Graphics:DrawTexture(Rect, Texture) Inventory:DrawInventory() (at Assets/Scripts/Inventory.cs:55) Inventory:OnGUI() (at Assets/Scripts/Inventory.cs:38) " for this script: using UnityEngine; using System.Collections; using System.Collections.Generic;
public class Inventory : MonoBehaviour {
public int slotsX, slotsY;
public GUISkin skin;
public List<Item> inventory = new List<Item>();
public List<Item> slots = new List<Item>();
private bool showInventory;
private ItemDatabase database;
void Start () {
for(int i = 0; i < (slotsX * slotsY); i++)
{
slots.Add(new Item());
inventory.Add (new Item());
}
database = GameObject.FindGameObjectWithTag("ItemDatabase").GetComponent<ItemDatabase>();
inventory[0] = database.items[0];
inventory[1] = database.items[1];
}
void Update()
{
if(Input.GetButtonDown("Inventory"))
{
showInventory = !showInventory;
}
}
void OnGUI ()
{
GUI.skin = skin;
if (showInventory)
{
DrawInventory();
}
}
void DrawInventory()
{
int i = 0;
for (int x = 0; x < slotsX; x++)
{
for (int y = 0; y < slotsY; y++)
{
Rect slotRect = new Rect(x * 60, y * 60, 50, 50);
GUI.Box(slotRect, "", skin.GetStyle("Slot"));
slots[i] = inventory[i];
if(slots[i].itemName != null)
{
Graphics.DrawTexture(slotRect, slots[i].itemIcon);
}
i++;
}
}
}
}
Comment
What sets the itemIcon
? The error says that this is null, so maybe you've not initialised the slots correctly.
Your answer
Follow this Question
Related Questions
rotation problem 1 Answer
Can you help me find the script error please? 1 Answer
< INT_MIN || f > INT_MAX targeting error 1 Answer
Changing Texture2D at runtime, but it doesent work? 0 Answers
Why is my texture like this? 1 Answer