用c#协程有什么办法能暂停么?我只看见stop。

linjiangxian11 linjiangxian11 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
写了个分几轮出怪的协程,协程正常运行,但忽然发现无法暂停这个协程,用Stop就完全中断,再Start又重新开始。

不知有什么办法能让它暂停么?文中粗体字标记了重点。

求救,谢谢。

     public  float roundIntervalTime = 3f;
public float spawIntervalTime = 1f;

IEnumerator RunRound()
{
if (isPause)
{

yield return null;
//有什么办法暂停
}
//SpawnMonsterArgs e = new SpawnMonsterArgs();
for (int r = 0; r < lstRound.Count; r++)
{
//这里可以加入StartRound事件,例如可触发最后一波
roundIndex = r;
for (int i = 0; i < lstRound[r].monsterCount; i++)
{
//e.monsterID = lstRound[r].monsterID;
//SendEvent(Consts.E_SpawnMonster, e);
if (r == (lstRound.Count - 1) && (i == lstRound[r].monsterCount - 1))
{
Debug.Log(" round is end !");
}
else
{
Debug.Log("Round: r:" + r + ", i:" + i);
}
yield return new WaitForSeconds(spawIntervalTime);
}
yield return new WaitForSeconds(roundIntervalTime);
}

}

public void StartRound()
{
coroutine= Game.Instance.StartCoroutine(RunRound());
Debug.Log("RoundModel.StartRound()");
}

public void StopRound()
{
//Game.Instance.StopCoroutine(coroutine);
isPause = !isPause;
Debug.Log("isPause: "+isPause);
}
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
linjiangxian11
C# 111,129 成员 642,539 内容