using System; using UnityEngine; using System.Collections; using System.Collections.Generic; using Assets.Scripts; using UnityEngine.UI; public class UIController : MonoBehaviour { public Text Distance; public Text Score; public Text HighScore; public Text NbVials; public Image Vial1; public Image Vial2; public Image Vial3; public Image Battery; public Image Progression; public Sprite[] ProgressionSprites; public List<Sprite> BatteryImages; private Player _player; private int _oldHs; void Start () { _player = GameObject.FindWithTag("Player").GetComponent<Player>(); HighScore.enabled = false; Vial1.enabled = false; Vial2.enabled = false; Vial3.enabled = false; _oldHs = PlayerPrefs.GetInt("highscore"); } void Update () { Distance.text = (int.Parse(Distance.text) + 1).ToString(); _player.Score += 1; Score.text = _player.Score.ToString(); NbVials.text = _player.NbVials.ToString(); DisplayBattery(); HandlePowerUps(); HandleScore(); } private void HandleScore() { if (_oldHs < _player.Score) HighScore.enabled = true; } private void HandlePowerUps() { if (_player.NbVials >= 5) Vial1.enabled = true; if (_player.NbVials >= 10) Vial2.enabled = true; if (_player.NbVials >= 15) Vial3.enabled = true; } private void DisplayBattery() { Battery.sprite = BatteryImages[_player.Battery/8]; Progression.sprite = ProgressionSprites[_player.Progression / 5]; } }