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 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");
}
}