Hello. I want to be able to only have 1 enemy in my scene at a time. I have a script for spawning my enemies, but the enemies clone themselves. Help is appreciated ![]()
Why would the enemies clone themselves unless you specifically coded them too? And if you only want 1 enemy at a time why would code them to clone? Maybe post the code that is instantiating enemies?
If they are only being spawed from one script you can easily do this in your script
private static int enemyCount = 0;
// Code where you spawn an enemy
if (enemyCount == 0)
{
// Spawn your enemy with instantiate here
enemyCount++;
}
// Whenever an enemy is killed it needs to call this
public void EnemyDestroyed()
{
enemyCount--;
}
So even if you have this script attached to lots of things, the static keyword will make the enemyCount shared among all of them.