Question by
Jack_Loomis · Feb 27, 2019 at 12:26 AM ·
2dintenemiessubtractingspace invaders
Subtracting from enemies left variable not working on collision
I am working on a space invaders like project. I am trying to see how many enemies are left using an int. I subtract one from the int when a bullet hits a game object with an enemy tag.
Here's my code:
void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "Enemy")
{
enemiesLeft--;
}
}
What ends up happening is every time I hit an enemy, the int just stays at 32. Any help with this, or any alternative ways to detect how many enemies are left would be much appreciated.
Thanks!
Comment