0
\$\begingroup\$

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:

enter image description here

\$\endgroup\$
  • 4
    \$\begingroup\$ 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? \$\endgroup\$ – Qfwfq Mar 10 at 0:18
0
\$\begingroup\$

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.

Provide more information if your problem isn't solved from these two cases.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.