UPF/Assets/Game/Scenes/TestScene/TestSceneScripts/MineScript.cs
2023-02-24 22:14:55 +05:30

43 lines
917 B
C#
Executable File

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;
}
}