Well I did a script to create small bars of life on top of the character, until then everything is ok, it’s following him and everything ok, but the problem is that it has a delay, for example the player arrives first and dps it arrives, leave it fixed to the player ?, script:
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();
}
}
GIF of how to be <<< CLICK
MichaI
2
I assume you made sliders in fixed position on UI canvas so it follows player when camera follows him. Because camera softly follows player the sliders seems to have delay. You can move sliders by script to be always exactly above your player. One way to do this is create empty GameObject right above your player as his child and set his transform as target for sliders to follow in script:
public Camera camera;
public Transform targetToFollow;
public RectTransform sliderTransform;
...
sliderTransform.position = camera.WorldToScreenPoint(targetToFollow.position);
In your case it will be probably something like this:
using UnityEngine;
using UnityEngine.UI;
public partial class UIMiniHealthMana : MonoBehaviour
{
public GameObject panel;
public Slider healthSlider;
public Slider manaSlider;
public Transform targetToFollow;
public Camera camera;
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();
panel.GetComponent<RectTransform>().position = camera.WorldToScreenPoint(targetToFollow.position);
}
}