healthbar now calculates based on percentage of live
This commit is contained in:
parent
e487e1038d
commit
4e17aefb34
2 changed files with 24 additions and 7 deletions
|
@ -48,4 +48,8 @@ public abstract class Mob : Entity {
|
|||
public int getHealth() {
|
||||
return currentHP;
|
||||
}
|
||||
|
||||
public int getMaxHealth() {
|
||||
return maxHP;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,25 +5,38 @@ using UnityEngine;
|
|||
public class HealthbarController : MonoBehaviour {
|
||||
|
||||
float currentRotation;
|
||||
float maxRotation;
|
||||
private Player player;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
player = GameController.instance.GetPlayer();
|
||||
currentRotation = 100f;
|
||||
UpdatePlayer();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
// if player alive and spawned
|
||||
if (player != null) {
|
||||
gameObject.transform.Rotate(Vector3.forward, -(currentRotation - player.getHealth()));
|
||||
currentRotation = player.getHealth();
|
||||
UpdatePointer(player.getHealth());
|
||||
} else {
|
||||
//if player dead or not spawned
|
||||
gameObject.transform.Rotate(Vector3.forward, -currentRotation);
|
||||
currentRotation = 0f;
|
||||
player = GameController.instance.GetPlayer();
|
||||
UpdatePointer(0);
|
||||
UpdatePlayer();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue