Files
3DBlobici-WorkingTitle/3D blobici/Assets/Scripts/PotionsSkills/PotionHandler.cs

68 lines
1.6 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PotionHandler:MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
private Dictionary<PotionType, int> potions = new Dictionary<PotionType, int>();
2025-08-02 15:35:39 +02:00
[SerializeField] private TMP_Text textMeshProUGUI;
2025-08-02 23:20:20 +02:00
[SerializeField] private PotionHandler.PotionType potionType;
public enum PotionType
{
HealthSmall,
HealthBig,
Mana,
None
}
2025-08-02 15:35:39 +02:00
private void Awake()
{
foreach (PotionType type in System.Enum.GetValues(typeof(PotionType)))
{
potions.Add(type, 0);
}
2025-08-02 15:35:39 +02:00
textMeshProUGUI.text = potions[potionType].ToString();
2025-08-02 15:35:39 +02:00
// Register this handler with the PlayerSkillTree
PlayerSkillTree.Instance.RegisterPotionHandler(potionType, this);
}
public void AddPotion(PotionType type, int amount = 1)
{
potions[type] += amount;
if(type == potionType)
{
textMeshProUGUI.text= potions[type].ToString();
}
2025-08-02 15:35:39 +02:00
Debug.Log("Potion text is: " + textMeshProUGUI.text);
}
public bool UsePotion(PotionType type, int amount = 1)
{
potions[type] -= amount;
2025-08-02 15:35:39 +02:00
if (type == potionType)
{
textMeshProUGUI.text = potions[type].ToString();
}
return true;
}
public int GetAmount(PotionType type)
{
return potions[type];
}
public bool IsEmpty(PotionType type)
{
return GetAmount(type) == 0;
}
}