using System; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UI; public class HoldToLoadLevel : MonoBehaviour { public float holdDuration = 1f; // How long you have to hold down for public Image fillCircle; private float holdTimer = 0f; private bool isHolding = false; public static event Action OnHoldComplete; void Update() { if (isHolding) { holdTimer += Time.deltaTime; fillCircle.fillAmount = Mathf.Clamp01(holdTimer / holdDuration); if (holdTimer >= holdDuration) { // Safely invoke the event if there are subscribers OnHoldComplete?.Invoke(); ResetHold(); } } } // Called by the input system when hold input changes public void OnHold(InputAction.CallbackContext context) { if (context.started) { isHolding = true; } else if (context.canceled) { ResetHold(); } } private void ResetHold() { isHolding = false; holdTimer = 0f; fillCircle.fillAmount = 0f; } }