Created
April 1, 2020 14:30
-
-
Save Dssdiego/f732e6c40a03ccfa10daab1306336194 to your computer and use it in GitHub Desktop.
Unity Action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Events; | |
public class Money : MonoBehaviour | |
{ | |
[SerializeField] private int amount = 10000; | |
public static UnityAction<int> OnGrabbed; | |
public void Grab() | |
{ | |
OnGrabbed.Invoke(amount); | |
Destroy(gameObject); | |
// TODO: A Player can only pick X amount | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using TMPro; | |
using UnityEngine; | |
public class MoneyHUD : MonoBehaviour | |
{ | |
private TextMeshProUGUI moneyUI; | |
private int money; | |
void Start() | |
{ | |
moneyUI = GetComponent<TextMeshProUGUI>(); | |
money = 0; | |
moneyUI.SetText("" + 0); | |
Money.OnGrabbed += OnMoneyGrabbed; | |
} | |
private void SetMoneyAmount(int amount) | |
{ | |
moneyUI.SetText($"{Convert.ToDecimal(amount) / 100:#.00}"); | |
} | |
private void OnMoneyGrabbed(int amount) | |
{ | |
money += amount; | |
SetMoneyAmount(money); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment