blob: af13f99fe3bd287df2a69744e1287e7c9774d9b2 (
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
|
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;
int displayedScore;
int displayedMoney;
void Start() {
canvas = transform.GetChild (0).gameObject;
txtMoney = canvas.transform.Find ("playerMoney").gameObject.GetComponent <Text>();
txtScore = canvas.transform.Find ("playerScore").gameObject.GetComponent <Text>();
}
void Update () {
if (Player.money () != displayedMoney) {
displayedMoney = Player.money ();
updateMoney (displayedMoney);
}
if (Player.score () != displayedScore) {
displayedScore = Player.score ();
updateScore (displayedScore);
}
}
void updateScore(int newScore) {
txtScore.text = ("Score: " + newScore.ToString ());
}
void updateMoney(int newMoney) {
txtMoney.text = ("Money: " + newMoney.ToString () + "$");
}
}
|