Hi! I am currently having problems with the OnDestroy function. I have 3 Classes, PickUp, AddGold and Player.
When my character collide with a treasure the PickUp script destroys it. The AddGold should then start a function in the Player class.
PickUp:
void OnTriggerEnter2D(Collider2D other){
if (other.gameObject.tag=="Player") {
Destroy (this.gameObject);
}
}
}
AddGold:
public Player playerScript;
public int gold;
void onDestroy(){
playerScript.addGold (gold);
}
}
And Player has this function in it
public void addGold(int gold){
goldAmount += gold;
}
Why doesnt this work?