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;
|
2018-04-22 12:52:43 +02:00
|
|
|
|
float maxRotation;
|
2018-04-23 21:47:29 +02:00
|
|
|
|
Player player;
|
2018-04-22 01:15:56 +02:00
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
// Update is called once per frame
|
2018-04-23 21:24:53 +02:00
|
|
|
|
void Update()
|
|
|
|
|
{
|
2018-04-22 11:45:12 +02:00
|
|
|
|
// if player alive and spawned
|
2018-04-23 21:24:53 +02:00
|
|
|
|
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());
|
2018-04-23 21:24:53 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-22 11:45:12 +02:00
|
|
|
|
//if player dead or not spawned
|
2018-04-22 12:52:43 +02:00
|
|
|
|
UpdatePointer(0);
|
2018-04-22 11:45:12 +02:00
|
|
|
|
}
|
2018-04-22 15:59:14 +02:00
|
|
|
|
}
|
2018-04-22 12:52:43 +02:00
|
|
|
|
|
2018-04-23 21:24:53 +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;
|
2018-04-22 12:52:43 +02:00
|
|
|
|
gameObject.transform.Rotate(Vector3.forward, offset);
|
|
|
|
|
currentRotation += offset;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 15:59:14 +02:00
|
|
|
|
public void SetPlayer(Player ply) {
|
|
|
|
|
player = ply;
|
2018-04-23 21:24:53 +02:00
|
|
|
|
maxRotation = player.GetMaxHealth();
|
2018-04-23 21:47:29 +02:00
|
|
|
|
//currentRotation = (player.GetHealth() / maxRotation) * 100;
|
|
|
|
|
Debug.Log("Set Player");
|
2018-04-22 12:52:43 +02:00
|
|
|
|
}
|
2018-04-22 01:15:56 +02:00
|
|
|
|
}
|