From c6ce11ec82b49d4a59dc6a117b71195cefbc4a8c Mon Sep 17 00:00:00 2001 From: Soulaha Balde Date: Sat, 29 Oct 2022 22:49:26 -0400 Subject: [PATCH] Collected coin amount is tracked --- Assets/Scripts/Collectible.cs | 1 + Assets/Scripts/GameController.cs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Assets/Scripts/Collectible.cs b/Assets/Scripts/Collectible.cs index 51889aa..484cb1d 100644 --- a/Assets/Scripts/Collectible.cs +++ b/Assets/Scripts/Collectible.cs @@ -18,6 +18,7 @@ public class Collectible : MonoBehaviour private void OnTriggerEnter(Collider other) { if(other.gameObject.tag.Equals("Player")){ + GameController.Instance.AddCoins(amount); Vanish(); } } diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index af3aed7..2c91fb5 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -14,6 +14,8 @@ public class GameController : MonoBehaviour [SerializeField] private Image fadeImg; private Coroutine fadeCoroutine; + private int coinAmount = 0; + public int CoinAmount{get=>coinAmount;} public static GameController Instance{ get{ if(instance is null)Debug.LogError("Game controller is null"); @@ -31,6 +33,11 @@ public class GameController : MonoBehaviour } } + + public void AddCoins(int amount){ + //This should not be like this. Collectible should call the player that hit it and add to their amount + coinAmount += amount; + } public void StartGame(){