- Home /
How to Stop score from going into negatives, even with a proper script
I am trying to stop the score from entering the negatives so I have this code = if(Score < 0) {Score = 0}; However what this does, when I click a game object which is supposed to give me -3 score if I'm at the score 0, it still -3 but when I proceed to hit the gameobject one more timer the score does not proceed to -6 it stays at -3. This leads me to belive that it checks for the score after the object has been clicked. I dont know what to do as both the click object and score lines of code are in the update function.
Answer by Zuries · Jun 22, 2020 at 09:59 AM
try doing it in one method like below
public int currentScore;
Public void GainScore(int score) { currentScore += score;
if(currentScore <= 0)
{
currentscore = 0;
}
}
then call GainScore(-3) when clicking the object.
Your answer
Follow this Question
Related Questions
How to increment score by one, every time player moves the device face down ? 2 Answers
Audio won't play sound 2 Answers
When die - reset score from the last scene 2 Answers
How can I deal with multiple if-statements? 2 Answers
Can not click buttons in the animator (2d),Can not click buttons in the animator 0 Answers