39 lines
934 B
C#
39 lines
934 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public class Tools : MonoBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
public static IEnumerator AnimateText(float startValue, float endValue, float time, Text SetText)
|
|
{
|
|
float elapsedTime = 0f; // 已经过去的时间
|
|
while (elapsedTime < time)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
float t = elapsedTime / time;
|
|
|
|
// 计算当前值,使用 Mathf.Lerp 进行线性插值
|
|
int currentValue = Mathf.RoundToInt(Mathf.Lerp(startValue, endValue, t));
|
|
|
|
// 更新文本显示
|
|
SetText.text = currentValue.ToString();
|
|
|
|
yield return null; // 等待一帧
|
|
}
|
|
|
|
SetText.text = endValue.ToString();
|
|
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|