你好,我一直有麻烦弄清楚这个问题。基本上,我想让某些事情在10秒后发生,而不延迟开始函数或使用更新函数减慢帧的速度。我对团结有点陌生,所以如果有什么我需要提供的告诉我。谢谢!
有很多方法!下面是一些例子:
- 使用Unity协程(https://docs.unity3d.com/Manual/Coroutines.html)
void Start()
{
StartCoroutine(DoSomethingAfterTenSeconds());
}
IEnumerator DoSomethingAfterTenSeconds()
{
yield return new WaitForSeconds(10);
// now do something
}
- 使用
FixedUpdate
或Update
等待10秒:
private float _delay = 10;
public void FixedUpdate()
{
if (_delay > 0)
{
_delay -= Time.fixedDeltaTime;
if (_delay <= 0)
{
// do something, it has been 10 seconds
}
}
}
- 使用async/await代替协程(https://forum.unity.com/threads/c-async-await-can-totally-replace-coroutine.1026571/)