aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts/gameStats.cs
diff options
context:
space:
mode:
Diffstat (limited to 'td/Assets/Scripts/gameStats.cs')
-rw-r--r--td/Assets/Scripts/gameStats.cs43
1 files changed, 43 insertions, 0 deletions
diff --git a/td/Assets/Scripts/gameStats.cs b/td/Assets/Scripts/gameStats.cs
new file mode 100644
index 0000000..af13f99
--- /dev/null
+++ b/td/Assets/Scripts/gameStats.cs
@@ -0,0 +1,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 () + "$");
+ }
+
+}