我最近学习了 C# unity 中的协程,并尝试创建一个等待函数来在代码之间等待。它同时打印两个语句,而不是等待三秒钟。有谁知道这个问题的解决方案?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Learninghowtoprogram : MonoBehaviour
{
private void Start()
{
print("hello");
wait(3);
print("hello2");
}
IEnumerator waito(float time)
{
yield return new WaitForSeconds(time);
}
void wait(float time)
{
StartCoroutine(waito(time));
}
}
Run Code Online (Sandbox Code Playgroud)