# Make health bar follow the player not the camera

I wrote a script to create small bars of life & mana on top of the character.

So far it's following him and everything ok, but the problem is that it has a delay, for example the player arrives first and then the bars arrive shortly afterward.

How can I keep the bars it fixed to the player?

using UnityEngine;
using UnityEngine.UI;

public partial class UIMiniHealthMana : MonoBehaviour
{
public GameObject panel;
public Slider healthSlider;
public Slider manaSlider;

void Update()
{

Player player = Utils.ClientLocalPlayer();
panel.SetActive(player != null); // hide while not in the game world
if (!player) return;

healthSlider.value = player.HealthPercent();

manaSlider.value = player.ManaPercent();

}

}


Example of the error:

• I'm having trouble telling exactly what you've done to attach the bars to the character in the first place. Could you tell me about GameObject panel? Is it a child of the character? What other elements exist in the character? Mar 10 '19 at 0:18

Since you have not given any info about the GameObject, so i am guessing it could be one of these two.

1. Problem with your sprite animation. (As the health bar doesn't deviate too much and can be visualised within imaginary square, so it is possible that the animations are not in place, and the health bar is fine)

2. The GameObject Panel is not a child of the PlayerController.

Solution:

1. For the first case, you should look into your animations, so that they are in place.

2. For the second case, make the sure that the GameObject Panel is a child of PlayerController.