UIController.cs 1.24 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
using Assets.Scripts;
using UnityEngine.UI;

public class UIController : MonoBehaviour
{
    public Text Distance;
    public Text Score;
    public Text HighScore;
    public Text NbVials;
Raphael committed
14
    public Image Battery;
Raphael committed
15 16
    public Image Progression;
    public Sprite[] ProgressionSprites;
Raphael committed
17
    public List<Sprite> BatteryImages;
Raphael committed
18 19

    private Player _player;
Naliwe GS committed
20
    private int _oldHs;
Raphael committed
21 22 23 24

	void Start ()
	{
	    _player = GameObject.FindWithTag("Player").GetComponent<Player>();
Raphael committed
25
	    HighScore.enabled = false;
Naliwe GS committed
26
	    _oldHs = PlayerPrefs.GetInt("highscore");
Raphael committed
27 28 29 30
	}
	
	void Update ()
	{
Raphael committed
31
	    Distance.text = (int.Parse(Distance.text) + 1).ToString();
Raphael committed
32

Naliwe GS committed
33 34
	    _player.Score += 1;
	    Score.text = _player.Score.ToString();
Raphael committed
35 36
	    NbVials.text = _player.NbVials.ToString();

Raphael committed
37
	    DisplayBattery();
Raphael committed
38
	    HandlePowerUps();
Naliwe GS committed
39
	    HandleScore();
Raphael committed
40
	}
Raphael committed
41

Naliwe GS committed
42 43 44 45 46 47
    private void HandleScore()
    {
        if (_oldHs < _player.Score)
            HighScore.enabled = true;
    }

Raphael committed
48 49 50 51
    private void HandlePowerUps()
    {
    }

Raphael committed
52 53 54
    private void DisplayBattery()
    {
        Battery.sprite = BatteryImages[_player.Battery/8];
Raphael committed
55
        Progression.sprite = ProgressionSprites[_player.Progression / 5];
Raphael committed
56
    }
Raphael committed
57
}