救命啊!为什么 WaitForSeconds 的时间比实际时间慢半拍?
如题:
我已经用了 FixedUpdate 了怎么时间还是慢半拍的?有什么解决方法吗?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Spawner : MonoBehaviour
{
public RadialSlider slider;
public Button button;
void Start()
{
button.onClick.AddListener(OnClick);
button.interactable = true;
slider.timeRemaining = slider.maxTime;
}
void OnClick()
{
StartCoroutine(OnFixedUpdateRoutine());
}
IEnumerator OnFixedUpdateRoutine()
{
slider.timeRemaining = slider.maxTime;
button.interactable = false;
float fixedDeltaTime = Time.fixedDeltaTime;
for(float t = slider.maxTime; t > 0; t -= Time.fixedDeltaTime)
//for(float t = 0; t < slider.maxTime ; t += fixedDeltaTime)
{
slider.timeRemaining = t;
yield return new WaitForSeconds(fixedDeltaTime);
}
slider.timeRemaining = Time.time;
button.interactable = true;
}
}