OnDestroy not working properly?

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.


void OnTriggerEnter2D(Collider2D other){
	if (other.gameObject.tag=="Player") {
		Destroy (this.gameObject);




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?

Your “onDestroy” method is named incorrectly, it is case-sensitive and should be “OnDestroy” as remarked in the documentation for OnDestroy method, that should be the first thing you change.