using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class MineScript : MonoBehaviour { [HideInInspector] public TMP_Text txt; [HideInInspector] public TMP_Text gold; private int goldAmount = 0; private int totalAmount = 0; public float refreshTime = 0.2f; private void Start() { StartCoroutine(GetGoldTimer()); } private IEnumerator GetGoldTimer() { while (true) { yield return new WaitForSeconds(refreshTime); goldAmount++; UpdateGold(); } } private void UpdateGold() { gold.text = goldAmount.ToString(); } public void CollectGold() { totalAmount = goldAmount + totalAmount; txt.text = totalAmount.ToString(); goldAmount = 0; } }