I have this script here that will award gold to the player if the game object(AIPlayer) “dies” (if his health <= 0) And also it will destroy the game object, however there are 4 enemies in the scene, instantiated at runtime from a AIPlayer prefab. When one enemy reaches 0 health, all 4 are destroyed and the player is awarded the proper amount of gold for each kill. How can I set it to only destroy a specific object instead of the clones of the prefab that is currently destroying.
void Awake ()
{
currency = GameObject.FindGameObjectWithTag("GameManager").GetComponent<Currency>();
player = GameObject.FindGameObjectWithTag("AIPlayer").GetComponent<AIPlayer>();
}
void Update ()
{
if(player.HP <= 0)
{
Destroy(this.gameObject);
currency.CalculateGold(25);
}
else if(player.HP > 0)
{
}