using UnityEngine; using UnityEngine.UI; using System.Collections; public class HoldProgress : MonoBehaviour { public Image radialImage; private Coroutine progressCoroutine; void Awake() { if (radialImage != null) { radialImage.fillAmount = 0f; radialImage.gameObject.SetActive(false); } } // 開始 public void StartProgress(float seconds) { if (radialImage == null || seconds <= 0f) return; if (progressCoroutine != null) StopCoroutine(progressCoroutine); radialImage.gameObject.SetActive(true); progressCoroutine = StartCoroutine(ProgressCoroutine(seconds)); } // 中斷 public void StopProgress() { if (progressCoroutine != null) { StopCoroutine(progressCoroutine); progressCoroutine = null; } if (radialImage != null) { radialImage.fillAmount = 0f; radialImage.gameObject.SetActive(false); } } private IEnumerator ProgressCoroutine(float seconds) { float elapsed = 0f; while (elapsed < seconds) { elapsed += Time.deltaTime; radialImage.fillAmount = 1f - Mathf.Clamp01(elapsed / seconds); yield return null; } radialImage.fillAmount = 0f; radialImage.gameObject.SetActive(false); progressCoroutine = null; } }