blob: 7c305fad0caee52137f64486a62c6ce8f5b98064 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class GameStats : MonoBehaviour {
public Player Player;
GameObject _canvas;
Text _txtMoney;
Text _txtScore;
Text _txtHp;
int _displayedScore;
int _displayedMoney;
int _displayedHealth;
void Start() {
_canvas = transform.GetChild (0).gameObject;
_txtMoney = _canvas.transform.Find ("playerMoney").gameObject.GetComponent <Text>();
_txtScore = _canvas.transform.Find ("playerScore").gameObject.GetComponent <Text>();
_txtHp = _canvas.transform.Find ("playerHealth").gameObject.GetComponent <Text>();
}
void Update () {
if (Player.Money () != _displayedMoney) {
_displayedMoney = Player.Money ();
UpdateMoney (_displayedMoney);
}
if (Player.Score () != _displayedScore) {
_displayedScore = Player.Score ();
UpdateScore (_displayedScore);
}
if (Player.Health () != _displayedHealth) {
_displayedHealth = Player.Health ();
UpdateHealth (_displayedHealth);
}
}
void UpdateScore(int newScore) {
_txtScore.text = ("Score: " + newScore.ToString ());
}
void UpdateMoney(int newMoney) {
_txtMoney.text = ("Money: " + newMoney.ToString () + "$");
}
void UpdateHealth(int newHp) {
_txtHp.text = ("HP: " + newHp.ToString ());
}
}
|