Hi, I was wondering if someone could guide me on the right path for my problem. I was able to set up an HP bar for my enemies, but their scale always stays the same even when they’re far away. Is there a way to make it so that the HP bar’s scale would be relative to the enemy it’s attached to and not the camera?
This is the script I have so far:
function Update () {
myHB.transform.position = Camera.main.WorldToViewportPoint(transform.position);
myHB.transform.position.x -= 0.05;
myHB.transform.position.y += 0.3;
myHB.transform.localScale = Vector3.zero;
var healthPercent: float = curHealth / maxHealth;
healthBarWidth = healthPercent * 64;
myHB.guiTexture.pixelInset = Rect(10,10,healthBarWidth,4);
}