So I’m making a top-down 2D shooter in which enemy caps spawn, and I have a variable keeping track of the spawn count, the number of enemies currently in the scene. When an enemy is killed the variable decreases by 1. I was hoping to use C# to write a script which basically amounts to “If the spawnCount variable decreases by 1, Increase the score variable by 1.” I know how to increase the score variable, but I haven’t a clue how have the game find out if the spawnCount has decreased by 1. So would anybody know a way?
public int spawnCount;
public int score;
public int SpawnCount
{
get
{
return spawnCount;
}
set
{
int oldCountValue = spawnCount;
spawnCount = value;
if(spawnCount > oldCountValue)
{
score += spawnCount - oldCountValue;
}
}
}