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<MoneyCounter>().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);
}
}