Health Bar issue: https://i.gyazo.com/cfa5ee306193bdea7649821ea1b63933.gif
I was trying to make this script so the health bar would always stay horizontal and above the GameObject (player or enemy) no matter how they rotated but its still not working any ideas?
Health Bar Script:
using UnityEngine;
using UnityEngine.UI;
public class StatusIndicator : MonoBehaviour {
[SerializeField]
private RectTransform healthBarRect;
[SerializeField]
//private Text healthText;
private GameObject gameObject;
void Start()
{
if (healthBarRect == null)
{
Debug.LogError ("StatusIndicator Bar is Missing");
}
//if (healthText == null)
//{
//Debug.LogError("StatusIndicator Bar is Missing");
//}
}
void Update ()
{
healthBarRect.transform.position.Set(gameObject.transform.position.x, gameObject.transform.position.y+0.5f, gameObject.transform.position.z);
}
public void SetHealth(int _cur, int _max)
{
float _value = (float)_cur / _max;
healthBarRect.localScale = new Vector3(_value, healthBarRect.localScale.y, healthBarRect.localScale.z);
//healthText.text = _cur + "/" + _max + "HP";
}
}
i love you
– Derayne