I’ve been trying to make a health bar float over and follow an enemy. The problem is the bar doesn’t really stay over the enemies. By the way , this is for a 2d game. Here is the code so far:
var target : Transform;
function Update ()
{
var wantedPos = Camera.main.WorldToViewportPoint (target.position);
transform.position = wantedPos;
}
Update:
I’ve gotten the bar to follow the enemies but it still not in the right position and the bar now flashes left and right.
Why don’t you just parent the health bar to the enemy, that way it will always follow the enemies position.
That’s what I did I just needed to restart unity.
Now they’re flashing around the characters! What the heck?!
Are you using 2DTextures or GUI for the bars?
One thing I noticed when adding health bars over the heads of my game’s enemies is that the Y-axis seems to flip upside-down in there somewhere. Adding a line to invert the Y-axis actually stabilized the bar whereas before it seemed to be “all over the place” (actually moving erratically in the Y-axis due to the above issue)
Is that what you are seeing?