Implemented diamond counter

This commit is contained in:
Max 2025-02-25 10:41:33 +01:00
parent f2f6e8620a
commit ac4771f1da
24 changed files with 5336 additions and 118822 deletions

View file

@ -1,22 +1,39 @@
using System;
using TMPro;
using UnityEngine;
using UnityEngine.Serialization;
public class Player : MonoBehaviour
{
[SerializeField] private int maxHealth;
[SerializeField] private int diamonds;
[SerializeField] private GameObject healthGameObject;
[FormerlySerializedAs("healthGameObject")] [SerializeField] private GameObject healthGO;
[FormerlySerializedAs("DiamondsGO")] [SerializeField] private GameObject diamondsGO;
[SerializeField] private GameObject rooms;
private int _healthIndex = 0;
private readonly int[] _healthBar = {0, 0, -1, -2, -4, -6, -9, -12, -16, -20};
private void OnEnable()
{
RoomRewards.DiamondsRewarded += AddDiamonds;
RoomRewards.DamageDealt += TakeDamage;
ChestRewardSelection.DiamondAndLifeSelected += HandleDiamondAndLifeAbilitySelected;
}
private void OnDisable()
{
RoomRewards.DiamondsRewarded -= AddDiamonds;
RoomRewards.DamageDealt -= TakeDamage;
}
private void Start() {
UpdateGUI();
}
public void GetDiamonds(int count)
public void AddDiamonds(int count)
{
diamonds += count;
UpdateGUI();
}
public void TakeDamage(int damage)
@ -39,6 +56,13 @@ public class Player : MonoBehaviour
private void UpdateGUI()
{
healthGameObject.GetComponent<TextMeshProUGUI>().text = _healthBar[_healthIndex].ToString();
healthGO.GetComponent<TextMeshProUGUI>().text = _healthBar[_healthIndex].ToString();
diamondsGO.GetComponent<TextMeshProUGUI>().text = diamonds.ToString();
}
private void HandleDiamondAndLifeAbilitySelected()
{
Heal(1);
AddDiamonds(1);
}
}