This commit is contained in:
Alex38Lyon
2025-06-03 12:00:47 +02:00
parent ed8041abcd
commit 878ea46cac
1300 changed files with 527178 additions and 0 deletions
@@ -0,0 +1,33 @@
using Unity.FPS.Game;
using UnityEngine;
using UnityEngine.UI;
namespace Unity.FPS.UI
{
public class WorldspaceHealthBar : MonoBehaviour
{
[Tooltip("Health component to track")] public Health Health;
[Tooltip("Image component displaying health left")]
public Image HealthBarImage;
[Tooltip("The floating healthbar pivot transform")]
public Transform HealthBarPivot;
[Tooltip("Whether the health bar is visible when at full health or not")]
public bool HideFullHealthBar = true;
void Update()
{
// update health bar value
HealthBarImage.fillAmount = Health.CurrentHealth / Health.MaxHealth;
// rotate health bar to face the camera/player
HealthBarPivot.LookAt(Camera.main.transform.position);
// hide health bar if needed
if (HideFullHealthBar)
HealthBarPivot.gameObject.SetActive(HealthBarImage.fillAmount != 1);
}
}
}