Why my score it going down really fast when using Time.deltaTime? I’m trying to make a score system when every second you loss 1 point, but when I try to do this it make it go everything fast. I tried playing around with the TimeScale, fixed update, fixedtime and stuff but nothing to seem to work. Is this something have to do with the UI? What am I doing wrong? Here’s my code
The mistake you’ve made is that you increase the timer then take it away from the current score. So it won’t remove 1 a second it will remove the time elapsed every frame.
You can do something like this to get what you want. Alternatively you can change the line “score -=(int) timer;” to “score -= Time.deltaTime;”
public float timer = 0;
private string currentTime;
Text text;
int baseScore;
int curScore;
void Start() {
text = GetComponent<Text> ();
baseScore = 50000;
}
void Update() {
timer += Time.deltaTime;
currentTime = string.Format ("{0:0}", timer);
curScore = Mathf.RoundToInt(baseScore - (int) timer);
if (curScore < 0)
curScore = 0;
text.text = "" + curScore;
}