diff --git a/Assets/Scripts/HealthbarController.cs b/Assets/Scripts/HealthbarController.cs index 54b5bb5..86b3a7d 100644 --- a/Assets/Scripts/HealthbarController.cs +++ b/Assets/Scripts/HealthbarController.cs @@ -6,26 +6,36 @@ public class HealthbarController : MonoBehaviour { float currentRotation; float maxRotation; - private Player player; + Player player; // Update is called once per frame void Update() { // if player alive and spawned if (player != null) - { + { + Debug.Log(player.GetHealth()); UpdatePointer(player.GetHealth()); } else { //if player dead or not spawned UpdatePointer(0); - } } void UpdatePointer(float playerLife) { - float offset = playerLife - currentRotation; + float offset; + + if (player == null) { + currentRotation = 0; + offset = 0; + Debug.Log("Player not found"); + } else { + Debug.Log("calculated offset"); + offset = ((playerLife / maxRotation) * 100) - currentRotation; + } + gameObject.transform.Rotate(Vector3.forward, offset); currentRotation += offset; } @@ -33,6 +43,7 @@ public class HealthbarController : MonoBehaviour { public void SetPlayer(Player ply) { player = ply; maxRotation = player.GetMaxHealth(); - currentRotation = player.GetHealth(); + //currentRotation = (player.GetHealth() / maxRotation) * 100; + Debug.Log("Set Player"); } }