How do I get this script to keep count of specific game objects destroyed?

Hello everyone,
I am trying to create a script that keeps count of the amount of zombies the player destroys. If the player destroys 50 zombies then the win screen appears. I am having trouble getting my counter to count my destroyed Zombie game object. Here is my script:

var waveCounterText : GUIText;
var enemyCounterText : GUIText;
private var waveCount: int;
private var enemyCount: int;

function Start ()
{
waveCount = 0;
enemyCount = 0;
}

function Update ()
{
if(enemyCount >= 50)
{
waveCount++;
waveCounterText.Text(“Waves Completed:” + waveCount);
Application.LoadLevel(4);
}

 if (gameObject.tag == "zombie")
 {
 	enemyCount++;
 	enemyCounterText.Text("Zombies Killed:" + enemyCount);
}

}

Thank you everyone!!!

1 Answer

1

How you destroy your objects? You should count them there.
You can use Singleton object to store counter, or your own component attached to your camera or some global GameObject.