Quantcast
Channel: Questions in topic: "attach"
Viewing all articles
Browse latest Browse all 168

"Clipping", "Jumping" UI slider, attached to the 2d game object ( health bar)

$
0
0
,[GIF / jumping heathbar][1] [1]: https://i.stack.imgur.com/ivafd.gif 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. 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().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); } } }

Viewing all articles
Browse latest Browse all 168

Trending Articles