How to apply check on an instanced prefab

Hello,

I have the AI.cs script that keeps track when a unit dies etc.
I spawn a clone for the ‘RightGrunt’ prefab named ‘RightGrunt(Clone)’ (in Hierarchy)

How can I tell Unity :" For this spawned prefab, please give me 60 gold when it dies"?
This question is bugging me for the second week by now.

I tried in a separated script to check for the spawned unit like this :

void Update () {
	AI ai = GetComponent<AI>();
		if (ai.dead){ 
			Debug.Log("#################################################");
if (gameObject.name == "RightGrunt(Clone)"){gold += 60;
			}
}
		
	}

Without any success (it stops at the gameObject.name check).

I don’t know what to do anymore. I tried at least 12 different methods to make it work without any success.

Someone please help me. I’m prepared to even write a new gold reward script just to make this work.

Thank you for your time

This depends how you keep track of your gold.

One way would be to have a static variable, and then it would be as simple as MoneyManager.gold += 60.

If this is not good enough you’ll have to provide more details of how your code works.

I actually didn’t read most of this but I am sort of confused as to why this would be an issue. Just contact whatever inventory manager in the method you are using to “tear down” the grunt object. Generally if there is only a single instances of the inventory class I’ll just pack the entire class into a singleton and then let the other objects access it through that rather then making individual static variables or using access through the component system.

http://wiki.unity3d.com/index.php/Singleton

^ I highly recommend reading through this as singletons are AWESOME in unity IMO.