fixed HealthBar
This commit is contained in:
parent
199fcd8767
commit
8843cde650
1 changed files with 16 additions and 5 deletions
|
@ -6,7 +6,7 @@ public class HealthbarController : MonoBehaviour {
|
|||
|
||||
float currentRotation;
|
||||
float maxRotation;
|
||||
private Player player;
|
||||
Player player;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
|
@ -14,18 +14,28 @@ public class HealthbarController : MonoBehaviour {
|
|||
// 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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue