1
0
Fork 0

fixed HealthBar

This commit is contained in:
Jan 2018-04-23 21:47:29 +02:00
parent 199fcd8767
commit 8843cde650

View file

@ -6,26 +6,36 @@ public class HealthbarController : MonoBehaviour {
float currentRotation; float currentRotation;
float maxRotation; float maxRotation;
private Player player; Player player;
// 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)
{ {
Debug.Log(player.GetHealth());
UpdatePointer(player.GetHealth()); UpdatePointer(player.GetHealth());
} }
else else
{ {
//if player dead or not spawned //if player dead or not spawned
UpdatePointer(0); UpdatePointer(0);
} }
} }
void UpdatePointer(float playerLife) { 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); gameObject.transform.Rotate(Vector3.forward, offset);
currentRotation += offset; currentRotation += offset;
} }
@ -33,6 +43,7 @@ public class HealthbarController : MonoBehaviour {
public void SetPlayer(Player ply) { public void SetPlayer(Player ply) {
player = ply; player = ply;
maxRotation = player.GetMaxHealth(); maxRotation = player.GetMaxHealth();
currentRotation = player.GetHealth(); //currentRotation = (player.GetHealth() / maxRotation) * 100;
Debug.Log("Set Player");
} }
} }