Fix: Health Manager

Fixed an issue with health manager not responding properly to zero potions
This commit is contained in:
2025-09-04 01:54:39 +02:00
parent 63fede11cb
commit 3b07854bd1
3 changed files with 8 additions and 12 deletions

View File

@@ -21,18 +21,6 @@ public class HealthManager : MonoBehaviour
if (_healthText != null) if (_healthText != null)
_healthText.text = _currentHealth.ToString() + "/" + _maxHealth.ToString(); _healthText.text = _currentHealth.ToString() + "/" + _maxHealth.ToString();
// These are only for debugging!!!!
if(Input.GetKeyDown(KeyCode.K))
if(transform.tag == "Player")
ModifyHealth(-10);
if(Input.GetKeyDown(KeyCode.L))
ModifyHealth(10);
if (Input.GetKeyDown(KeyCode.M))
if(transform.tag == "Enemy")
ModifyHealth(-50);
} }
public void ModifyHealth(float amount) public void ModifyHealth(float amount)

View File

@@ -14,6 +14,7 @@ public class PlayerSkillHandler: MonoBehaviour
private Dictionary<PlayerSkillTree.Skills, float> cooldowns; private Dictionary<PlayerSkillTree.Skills, float> cooldowns;
private Dictionary<PlayerSkillTree.Skills, float> cooldownsActivated; private Dictionary<PlayerSkillTree.Skills, float> cooldownsActivated;
private PlayerSkillTree playerSkillTree; private PlayerSkillTree playerSkillTree;
private HealthManager healthManager;
private CharacterController controller; private CharacterController controller;
@@ -25,6 +26,7 @@ public class PlayerSkillHandler: MonoBehaviour
cooldownsActivated = new Dictionary<PlayerSkillTree.Skills, float>(); cooldownsActivated = new Dictionary<PlayerSkillTree.Skills, float>();
controller = GetComponent<CharacterController>(); controller = GetComponent<CharacterController>();
playerSkillTree = PlayerSkillTree.Instance; playerSkillTree = PlayerSkillTree.Instance;
healthManager = GetComponent<HealthManager>();
AssignCooldowns(); AssignCooldowns();
} }
@@ -45,6 +47,7 @@ public class PlayerSkillHandler: MonoBehaviour
if (playerSkillTree.TryUsePotion(PotionHandler.PotionType.HealthBig)) if (playerSkillTree.TryUsePotion(PotionHandler.PotionType.HealthBig))
{ {
Debug.Log("Potion used!"); Debug.Log("Potion used!");
healthManager.ModifyHealth(10);
} }
else else
{ {

View File

@@ -45,7 +45,12 @@ public class PotionHandler:MonoBehaviour
public bool UsePotion(PotionType type, int amount = 1) public bool UsePotion(PotionType type, int amount = 1)
{ {
if(potions[type] == 0)
return false;
potions[type] -= amount; potions[type] -= amount;
Debug.Log($"Amount of potions of type {type} is: {potions[type]}");
if (type == potionType) if (type == potionType)
{ {