_xiaofang/xiaofang/Assets/Res/gsj/scripts/chronograph.cs

51 lines
1.3 KiB
C#
Raw Normal View History

2024-12-20 10:10:19 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class chronograph : MonoBehaviour
{
private Image image;
public float duration = 3f; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>ʱ<EFBFBD><EFBFBD>
private float timer = 0f; // <20><>ʱ<EFBFBD><CAB1>
private bool isRunning = false; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
// Start is called before the first frame update
void Start()
{
image=transform.Find("Image/Image").GetComponent<Image>();
image.fillAmount = 0f; // <20><>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
StartProgressBar(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
// Update is called once per frame
void Update()
{
if (isRunning)
{
timer += Time.deltaTime;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>0 <20><> 1<><31>
float progress = timer / duration;
// <20><><EFBFBD><EFBFBD> Image <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
image.fillAmount = Mathf.Clamp01(progress);
// <20>жϽ<D0B6><CFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
if (timer >= duration)
{
isRunning = false;
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>");
}
}
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>
public void StartProgressBar()
{
timer = 0f;
isRunning = true;
if (image != null)
{
image.fillAmount = 0f; // <20><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD>
}
}
}