+ 1

What needs to be fixed in this code?

The problem is that when you lose, the score does not stop, but continues to go until you click on restart. And also, it does not save the highest score at all, there is simply 0 there. 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 &

27th Feb 2020, 10:54 AM
BIG BOSS
BIG BOSS - avatar
3 Answers
+ 2
It's my full code
27th Feb 2020, 11:08 AM
BIG BOSS
BIG BOSS - avatar
+ 1
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:07 AM
BIG BOSS
BIG BOSS - avatar