Health bars with Gameobjects - need help

Hey guys,

i decided to make health bars in our game (a student project) with game objects because we want to release the game on smartphones and guitextures need so much drawcalls (the health bars made of game objects need 1 because of batching).

However, i’ve encountered some serious problems:

First, the rotation. Every health bar is attached to the enemy gameobject for easier access and because of camera movement. But i don’t know how to make the bars look exactly at the screen. Right now i’m using

healthBar.transform.LookAt(Camera.main.transform.position);

but of course, the bars are looking at the camera, not at their screen position:

How can i make them look directly at the screen (like guitextures)?

On the Screen, you can see the second problem: if the game object is too far away, unity doesn’t give a **** that the green bar is in front of the grey one. How can i solve this one? I dont want to increase the distance between them because that looks weird if you take a closer look.

Third, there is a problem with the scaling.
Right now, to scale the bar to only one side, i try to move the bar on the x axis while scaling:

	private IEnumerator scaleBar(float hp, float points, GameObject target)
	{
		float factor = ((points / hp) / 10)*0.98f;
		for(int i = 0; i<10; i++)
		{
			Transform temp = (target.transform.Find("Lifebar(Clone)").transform.Find("Bar"));
			temp.transform.localScale -= new Vector3(factor,0f,0f);
			
			temp.transform.position += temp.transform.parent.rotation * new Vector3(factor/2.25f,0f,0f);
			yield return new WaitForSeconds(0.01f);
		}
	}

It kinda works, but the result is… ugly and weird.
After scaling it 10 times down (It never reaches 0% btw, also don’t know why) and 10 times up (right now the objects loses 10% of it’s health on activation, therefore 10 times is 100%), it looks like that:

How can i solve this?

Thanks for your help. :slight_smile:

A. dont look at the camera look at the opposite of the camera’s direction. Parallel to it

look at

-camera.transform.forward;

B. dont have a green bar in front of a grey one instead of removing green bars to expose the grey just the green bars and change the color when health is lost instead of exposing a background layer.