Files
Inter-Face-Off/Assets/Scripts/LifeThingTrackerThing.cs
Pasha Bibko e2c73f031c Hurt thingy
2026-01-27 13:25:23 +00:00

56 lines
1.4 KiB
C#

using System.Collections;
using JetBrains.Annotations;
using UnityEngine.UI;
using UnityEngine;
namespace InterfaceOff.WorldScene
{
public class LifeThingTrackerThing : MonoBehaviour
{
[SerializeField] private GameObject HurtOverlay;
[SerializeField] private Slider SliderThing;
private Rigidbody body;
private void Awake()
{
body = GetComponent<Rigidbody>();
}
void LateUpdate()
{
Vector3 pos = transform.localPosition;
pos.y = Mathf.Clamp(pos.y, 0, 10);
if (Mathf.Approximately(pos.y, 0.0f))
{
StartCoroutine(routine: DisplayHurtOverlay());
body.velocity = Vector3.zero;
pos.y = 10.0f;
}
if (Mathf.Approximately(pos.y, 10.0f))
{
body.velocity = Vector3.zero;
}
transform.localPosition = pos;
SliderThing.value = pos.y;
}
[UsedImplicitly] public void AddForceUp()
{
Vector3 vel = body.velocity;
body.AddForce(Vector3.up * 500f, ForceMode.Force);
}
private IEnumerator DisplayHurtOverlay()
{
HurtOverlay.SetActive(true);
yield return new WaitForSecondsRealtime(time: 0.1f);
HurtOverlay.SetActive(false);
}
}
}