小编Lle*_*ell的帖子

在 C# unity 中,我的等待函数未正确等待

我最近学习了 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)

c# unity-game-engine visual-studio

6
推荐指数
1
解决办法
741
查看次数

标签 统计

c# ×1

unity-game-engine ×1

visual-studio ×1