Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

NullReferenceException: Object reference not set to an instance of an object

$
0
0
#pragma strict import System.Collections.Generic; var loot : ItemClass[]; var Inventory : Inventory; function Start () { Inventory = GetComponent("Inventory") as Inventory; } function OnGUI() { GUILayout.BeginArea(Rect(0,0,500,050)); if(GUILayout.Button("Loot!")) { Giveloot(); } GUILayout.EndArea(); } function Giveloot(){ for(var x = 0; x < loot.length; x++){ Inventory.PlayerInventory.Add(loot[x]); } } I have this script, but it keeps saying NullReferenceException: Object reference not set to an instance of an object. I dont know whats wrong. All anwsers are appresiated.

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>