HealthBar

This commit is contained in:
2025-08-06 00:55:06 +02:00
parent ab75e6400e
commit 5afbf04037
4 changed files with 206 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class PlayerMovement : MonoBehaviour
{
@@ -11,15 +12,24 @@ public class PlayerMovement : MonoBehaviour
private CharacterController controller;
private Vector3 velocity;
private PlayerSkillTree PlayerSkills;
private int health;
private int maxHealth;
[Header ("Health")]
[SerializeField] private TMP_Text healthBar;
private void Awake()
{
PlayerSkills = PlayerSkillTree.Instance;
maxHealth = PlayerSkills.MaxHealth;
health = PlayerSkills.GetHealth();
Debug.Assert(maxHealth > 0);
}
void Start()
{
controller = GetComponent<CharacterController>();
healthBar.text = GetHealthText();
}
private void Update()
@@ -40,6 +50,17 @@ public class PlayerMovement : MonoBehaviour
Debug.Log("Potion not available!");
}
}
// TEMPORARY!!! LATER USED FOR COLISIONS
if (Input.GetKeyDown(KeyCode.F))
{
PlayerSkills.SetHealth(-20);
health = PlayerSkills.GetHealth();
healthBar.text = GetHealthText();
}
}
void FixedUpdate()
@@ -95,4 +116,9 @@ public class PlayerMovement : MonoBehaviour
{
return PlayerSkills.GetPlayerSkills();
}
private string GetHealthText()
{
return (health.ToString() + " / " + maxHealth.ToString());
}
}