hi, I’m trying to have a HP bar over each enemy in my game. As it is now I do have a bar that follows the enemy,but only in local coordinates. Converting it to world coordinated didn’t work…
Could I please have some help with this, or are there any other (better) ways to do this?
Here’s part of the code:
public class EnemyHealth : MonoBehaviour {
void Update ()
{
AddjustCurrentHealth(0);
pLeft = transform.position.x;
pTop = transform.position.z;
//*I believe this is how to convert the positions into World space, but it doesn't work.*//
//pLeft = transform.Translate(transform.position.x * Time.deltaTime, Space.World);
//pTop = transform.Translate(transform.position.z * Time.deltaTime, Space.World);
}
void OnGUI()
{
GUI.skin.box = style;
GUI.Box(new Rect(pLeft, pTop, healthBarLength, pHeight), curHealth + "/" + maxHealth);
}
}
I for the longest time have been looking for a working solution, and have only come close. As far as I know there are no good tutorials or scripts for having your gui follow the NPC’S.
Wish I could see it lol. It’s mega blurry on my screen. I do have a huge HD monitor but it doesn’t help. What video software do you use? I would love to see what code you used to get the gui to follow the npc’s correctly. One problem I’m having with my code is that the Gui gets bigger as the npc gets further away.
I looked at your tut, bugzilla, and it was very helpful. I’d like to use C# instead so I converted it, but since I’ve never used Instantiate before I do not know to use that line in C#… any tips?
Another question; how would you script the damage taken by the enemy with bugzillas hpbar? (Edit the hpbars length with different damage rates)
I would personaly advice to use 3D planes with textures instead of GUI components. No coordinate conversion is neded. And it could be much more efficient aswell since Unity’s GUI system isn’t too great.