- Home /
How to check if an int's value has decreased by 1?
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?
Answer by Mykhaylo-Hnatyuk · Jul 02, 2015 at 05:21 PM
public int spawnCount;
public int score;
public int SpawnCount
{
get
{
return spawnCount;
}
set
{
int oldCountValue = spawnCount;
spawnCount = value;
if(spawnCount > oldCountValue)
{
score += spawnCount - oldCountValue;
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613201513im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I move an obstacle in relation to a sloped line? (2D) 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
access instantiated object variable 0 Answers
2D platformer- getting errors I don't understand (c#) 1 Answer