Hello I am trying to make a game and keep getting this error message:
NullReferenceException: Object reference not set to an instance of an object
GUI_HUD.OnGUI () (at Assets/Scripts_/GUI_HUD.js:23).
And I for one have no idea what it means and my friend and I have trying to figure it out. The code of the GUI_HUD looks like this
var customSkin:GUISkin;
var EXPImage:Texture2D;
var healthpotionImage:Texture2D;
var manapotionImage:Texture2D;
private var customControls:GUI_CustomControls;
private var playerInvo:Player_Inventory;
function Awake()
{
customControls = FindObjectOfType(GUI_CustomControls);
playerInvo = FindObjectOfType(Player_Inventory);
}
function OnGUI()
{
if(customSkin)
{
GUI.skin = customSkin;
}
//Inventory Buttons --------------------------------------
if(customControls.InvoHudButton(Rect(10, Screen.height - 100, 93, 95), playerInvo.GetItemCount(InventoryItem.MANAPOTION), manapotionImage, "Click To Use a Mana Potion"))
{
playerInvo.UseItem(InventoryItem.MANAPOTION, 1);
}
if(customControls.InvoHudButton(Rect(110, Screen.height - 100, 93, 95), playerInvo.GetItemCount(InventoryItem.HEALTHPOTION),healthpotionImage, "Click To Use a Health Potion"))
{
playerInvo.UseItem(InventoryItem.HEALTHPOTION, 1);
}
//Non Usable Inventory Buttona ------------------------------
customControls.InvoHudButton(Rect(Screen.width - 210, Screen.height - 100, 93, 95), playerInvo.GetItemCount(InventoryItem.EXP), EXPImage, "Amount of EXP");
}
function Start () {
}
the GUI_CustomControls code looks like this
function InvoHudButton(screenPos: Rect, numAvailable : int, itemImage: Texture, itemtooltip: String ) : boolean
{
if( GUI.Button(screenPos, GUIContent(itemImage, itemtooltip), "HUD Button") )
{
return true;
}
GUI.Label( Rect(screenPos.xMax - 20, screenPos.yMax - 25, 20, 20 ), numAvailable.ToString() );
//display area for tooltips
GUI.Label( Rect( 20, Screen.height - 130, 500, 100), GUI.tooltip);
}