Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Receiving error"NullReferenceException: Object reference not set to an instance of an object clicktoDestroy.OnDestroy ()"

$
0
0
When clicking to destroy this game object I get an error that says "NullReferenceException: Object reference not set to an instance of an object clicktoDestroy.OnDestroy ()" Thanks in advance! ***Also im pooling clones of the game object that get deleted*** public class clicktoDestroy : MonoBehaviour { public Text moneytext; private int moneyamount; static GameObject MoneyPooler; private void Start() { moneyamount = 0; MoneyPooler = GameObject.Find("MoneyPooler"); } public void OnMouseDown() { Destroy(gameObject); } public void OnDestroy() { Debug.Log("+Money!"); MoneyPooler.GetComponent().IncreaseMoney(); } } ***And my money Counter which doesn't get destroyed*** public class MoneyCounter : MonoBehaviour { static GameObject money; static Text moneytext; static int score; public void Start() { score = 0; } public void IncreaseMoney() { moneytext.text = "$" + (score + 1); } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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