"Clipping", "Jumping" UI slider, attached to the 2d game object ( health bar)
My ui-slider jumps for no reason, i really don't understand what's happening. I have tried to change void Update() to FixedUpdate, but result same.
[,GIF / jumping heathbar][1] [1]: https://i.stack.imgur.com/ivafd.gif
my code:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthBarUi : MonoBehaviour
{
public Slider Slider;
public Color Low;
public Color High;
public Vector3 Offset;
public EnemyHealth healthofenemy;
public void SetHealth(float health, float maxHealth)
{
Slider.gameObject.SetActive(health < maxHealth);
Slider.value = health;
Slider.maxValue = maxHealth;
Slider.fillRect.GetComponentInChildren<Image>().color = Color.Lerp(Low, High, Slider.normalizedValue);
}
void Update()
{
SetHealth(healthofenemy.currentHP, healthofenemy.maxHP);
Slider.transform.position = Camera.main.WorldToScreenPoint(transform.parent.position + Offset);
if (healthofenemy.currentHP <= 0f)
{
gameObject.SetActive(false);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
"Clipping", "Jumping" UI slider, attached to the 2d game object ( health bar) 0 Answers
Healthbar/UI Slider glow effect 1 Answer
Slider Component Problem (Health Bar) 1 Answer
Player Health Glitch? 0 Answers
Need help syncing healthbar 0 Answers