I have this line of code that destroys a child of a prefab (works) and also I want to check for a certain spawned prefab and increase my gold by 20 if it dies (does not work).
if (ai && !ai.dead){ // if ai.dead not set yet...
ai.dead = true; // set it and destroy capsule
Destroy(transform.Find("Capsule").gameObject);
if (gameObject.name == "RightGrunt(Clone)"){gold += 20;}
}
Apparently it doesn’t work because it is a spawned prefab. If I do this with the same prefab set in the scene it works. How can apply the if for the spawned prefab ?
Code is in C#