unity 中的协程是否有与 async.then 等价的东西(就像在 JS 中一样)?

问题描述 投票:0回答:1

所以我有一个变量 isMoving,当协程结束时它应该变成 false。比如:


if (m_IsMoving == false){
    
    m_IsMoving = true;
    StartCoroutine(time_passed.Tweeng((time_Set_Movement) => 
        transform.position = time_Set_Movement,
        transform.position, 
        new Vector3(transform.position.x + positior.x,
        transform.position.y + positior.y, transform.position.z + positior.z) );
    // I am searching for some way to continue the coroutine with
    then{ m_IsMoving = false;}
    
}

有没有一种简单的方法可以在协程结束后添加类似的内容?

c# unity-game-engine
1个回答
0
投票

最简单的选择是更改协程内的值。有点喜欢

private _someBool = false;

private void SomeMethod()
{
    StartCoroutine(CoSomeCoroutine());
}

private IEnumeratoe CoSomeCoroutine()
{
    _someBool = true;
    
    // do your stuff here
    
    _someBool = false;
}
© www.soinside.com 2019 - 2024. All rights reserved.