1
0
Fork 0

healthbar now calculates based on percentage of live

This commit is contained in:
Jan 2018-04-22 12:52:43 +02:00
parent e487e1038d
commit 4e17aefb34
2 changed files with 24 additions and 7 deletions

View file

@ -48,4 +48,8 @@ public abstract class Mob : Entity {
public int getHealth() { public int getHealth() {
return currentHP; return currentHP;
} }
public int getMaxHealth() {
return maxHP;
}
} }

View file

@ -5,25 +5,38 @@ using UnityEngine;
public class HealthbarController : MonoBehaviour { public class HealthbarController : MonoBehaviour {
float currentRotation; float currentRotation;
float maxRotation;
private Player player; private Player player;
// Use this for initialization // Use this for initialization
void Start () { void Start () {
player = GameController.instance.GetPlayer(); UpdatePlayer();
currentRotation = 100f;
} }
// Update is called once per frame // Update is called once per frame
void Update () { void Update () {
// if player alive and spawned // if player alive and spawned
if (player != null) { if (player != null) {
gameObject.transform.Rotate(Vector3.forward, -(currentRotation - player.getHealth())); UpdatePointer(player.getHealth());
currentRotation = player.getHealth();
} else { } else {
//if player dead or not spawned //if player dead or not spawned
gameObject.transform.Rotate(Vector3.forward, -currentRotation); UpdatePointer(0);
currentRotation = 0f; UpdatePlayer();
player = GameController.instance.GetPlayer();
} }
} }
private void UpdatePointer(float playerLife) {
float offset = playerLife - currentRotation;
gameObject.transform.Rotate(Vector3.forward, offset);
currentRotation += offset;
}
private void UpdatePlayer() {
player = GameController.instance.GetPlayer();
if (player != null) {
maxRotation = player.getMaxHealth();
currentRotation = player.getHealth();
}
}
} }