0

The problem is that when you lose, the score does not stop, but continues to go until you click on restart. What l must fix?

Also, generally does not save the last score in the game, there is simply 0 there. The code : using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GameControl : MonoBehaviour { public int scorePlayer; [SerializeField] public int highScore = 0; private float timer; [SerializeField] public Text txt; public Text hightxt; public bool lose; void Start() { } void Update() { hightxt.text = "High Score: " + highScore; txt.text = "Your Score: " + scorePlayer; if (lose == false) timer += 1 * Time.deltaTime; if (lose == true) { if (highScore < scorePlayer) { highScore = scorePlayer; hightxt.text = "High Score: " + highScore; } timer = 1 * Time.deltaTime; } if (timer > 1 && lose == false) { scorePlayer += 1; timer = 0; } } }

27th Feb 2020, 11:25 AM
BIG BOSS
BIG BOSS - avatar
2 Respuestas
+ 1
I think that the last if must have only the second and not the timer >1 to stop the time if you lose
27th Feb 2020, 4:43 PM
Σταυρος
Σταυρος - avatar
0
Thanks a lot
27th Feb 2020, 4:44 PM
BIG BOSS
BIG BOSS - avatar