1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/HealthbarController.cs

49 lines
1.2 KiB
C#
Raw Permalink Normal View History

2018-04-22 01:15:56 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthbarController : MonoBehaviour {
2018-04-22 11:45:12 +02:00
float currentRotation;
float maxRotation;
2018-04-23 21:47:29 +02:00
Player player;
2018-04-22 01:15:56 +02:00
// Update is called once per frame
void Update()
{
2018-04-22 11:45:12 +02:00
// if player alive and spawned
if (player != null)
2018-04-24 01:28:18 +02:00
{
2018-04-23 23:14:41 +02:00
//Debug.Log(player.GetHealth());
2018-04-22 16:20:25 +02:00
UpdatePointer(player.GetHealth());
}
else
{
2018-04-22 11:45:12 +02:00
//if player dead or not spawned
UpdatePointer(0);
2018-04-22 11:45:12 +02:00
}
}
void UpdatePointer(float playerLife) {
2018-04-23 21:47:29 +02:00
float offset;
if (player == null) {
2018-04-24 01:28:18 +02:00
offset = -currentRotation;
2018-04-23 21:47:29 +02:00
Debug.Log("Player not found");
} else {
2018-04-23 23:14:41 +02:00
//Debug.Log("calculated offset");
2018-04-23 21:47:29 +02:00
offset = ((playerLife / maxRotation) * 100) - currentRotation;
}
2018-04-24 01:28:18 +02:00
offset /= 10;
gameObject.transform.Rotate(Vector3.forward, offset);
currentRotation += offset;
}
public void SetPlayer(Player ply) {
player = ply;
maxRotation = player.GetMaxHealth();
2018-04-23 21:47:29 +02:00
//currentRotation = (player.GetHealth() / maxRotation) * 100;
Debug.Log("Set Player");
}
2018-04-22 01:15:56 +02:00
}