- Home /
How do I stop adding to a variable?
How do I stop adding to score once something happens? For example, once my player dies, how do I stop the score from continuing to add?
public int score;
void Update()
{
score++;
}
You need to come up with some logic. How does the player die, you can use a bool for example callel, playerAlive which you keep true until he dies when you would set it to false, and you need to check if playerAlive is true before increasing the score, if he is not, don't increase it. If none of this sounds familiar, I suggest taking some tutorials to start wrapping your head around the basics
Answer by juliacs · Jun 06, 2019 at 06:10 PM
I think this is basic programming knowledge. Please try to learn a programming language before jumping into Unity (you can start with C/C++ since Unity uses C# and they have little difference)
Basically what you would want to do is put an if statement instead of simply increase the score. Example:
public int score;
public bool isAlive;
void Start()
{
isAlive = true;
}
void Update()
{
if (isAlive)
score++;
else
// ...
// shows game over screen with max score, etc
}
Thank you, yes I am new to program$$anonymous$$g, but I should know this, for whatever reason I couldn’t come up with the correct logic. I’m currently just fiddling around with Unity, not doing anything major.
Thank you though!
Your answer
Follow this Question
Related Questions
How to increase score for objects that form larger geometries? 0 Answers
Int Variable++ isn't adding anything. 4 Answers
Scoring System 3 Answers
How to make a Score GUI. 0 Answers
How do I do I time-base score script 0 Answers