blob: daeb3cfbf89cf83b8ddae9c3c7bae94916688fbe (
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 ());
}
}
|