- Home /
How do you stop a score counter when you die
using UnityEngine; using System.Collections;
public class Score : MonoBehaviour { public static float scorecounter = 0.0f; public GUIText Scoretext; void Update() { scorecounter = scorecounter + Time.deltaTime; Scoretext.text = "Score: " + scorecounter * 5; } }
So far I have this as my score counter and I stuck it on a GUI text. But I cant figure out how I would actually stop the timer upon the player colliding with an object.
Hi, can you please format your code using the 101010 button so we can read it, thanks :)
As a starter to your solution you should wrap all the code in your Update() that relates to the score counter in an :
if (Player_Is_Alive) {
//your score counter code...
}
where Player_Is_Alive is a Bool, when your player is dead set this to false and it won't run your score counter code in Update(), set back to true when the player is re-spawned/alive again.
Your answer
![](https://koobas.hobune.stream/wayback/20220613172026im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Skipping over timer 1 Answer
Countdown Timer or WaitForSeconds? 2 Answers
How to Set the Game Speed Based on the Player's Current Score? 1 Answer