UIController.cs 1.59 KB
Newer Older
Raphael committed
1 2 3
using System;
using UnityEngine;
using System.Collections;
Raphael committed
4
using System.Collections.Generic;
Raphael committed
5 6 7 8 9 10 11 12 13 14 15 16
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;
Raphael committed
17
    public Image Battery;
Raphael committed
18 19
    public Image Progression;
    public Sprite[] ProgressionSprites;
Raphael committed
20
    public List<Sprite> BatteryImages;
Raphael committed
21 22

    private Player _player;
Naliwe GS committed
23
    private int _oldHs;
Raphael committed
24 25 26 27

	void Start ()
	{
	    _player = GameObject.FindWithTag("Player").GetComponent<Player>();
Raphael committed
28
	    HighScore.enabled = false;
Raphael committed
29 30 31
	    Vial1.enabled = false;
	    Vial2.enabled = false;
	    Vial3.enabled = false;
Naliwe GS committed
32
	    _oldHs = PlayerPrefs.GetInt("highscore");
Raphael committed
33 34 35 36
	}
	
	void Update ()
	{
Raphael committed
37
	    Distance.text = (int.Parse(Distance.text) + 1).ToString();
Raphael committed
38

Naliwe GS committed
39 40
	    _player.Score += 1;
	    Score.text = _player.Score.ToString();
Raphael committed
41 42
	    NbVials.text = _player.NbVials.ToString();

Raphael committed
43
	    DisplayBattery();
Raphael committed
44
	    HandlePowerUps();
Naliwe GS committed
45
	    HandleScore();
Raphael committed
46
	}
Raphael committed
47

Naliwe GS committed
48 49 50 51 52 53
    private void HandleScore()
    {
        if (_oldHs < _player.Score)
            HighScore.enabled = true;
    }

Raphael committed
54 55 56 57 58 59 60 61 62 63
    private void HandlePowerUps()
    {
        if (_player.NbVials >= 5)
            Vial1.enabled = true;
        if (_player.NbVials >= 10)
            Vial2.enabled = true;
        if (_player.NbVials >= 15)
            Vial3.enabled = true;
    }

Raphael committed
64 65 66
    private void DisplayBattery()
    {
        Battery.sprite = BatteryImages[_player.Battery/8];
Raphael committed
67
        Progression.sprite = ProgressionSprites[_player.Progression / 5];
Raphael committed
68
    }
Raphael committed
69
}