【发布时间】:2018-09-17 22:44:46
【问题描述】:
我有一个 Unity3D 游戏,在这个游戏中有一个类似 iMimic 的游戏。
这里的问题是,所有代码都能完美运行,但它有一个细节,
游戏按以下顺序运行:
, (如您所见,全部在一起),但我需要它像这样运行:
也许这是 foeach 循环或 IEnumerators 的细节?
void Randomizer()
{
PreList = PreList.OrderBy(C => Rnd.Next()).ToArray();
foreach (var item in PreList)
{
Debug.Log(item.ToString());
if (item == 1)
{
StartCoroutine(OneMethod());
}
if (item == 2)
{
StartCoroutine(TwoMethod());
}
if (item == 3)
{
StartCoroutine(ThreeMethod());
}
}
IEnumerator OneMethod()
{
ButtonList.Add(1);
GameObject.Find("Red").GetComponent<Image>().color = Color.gray;
//Sound
yield return new WaitForSeconds(1);
GameObject.Find("Red").GetComponent<Image>().color = Color.white;
Debug.Log("Everyone");
yield return new WaitForSeconds(1);
}
IEnumerator TwoMethod()
{
ButtonList.Add(2);
GameObject.Find("Blue").GetComponent<Image>().color = Color.gray;
yield return new WaitForSeconds(1);
GameObject.Find("Blue").GetComponent<Image>().color = Color.white;
Debug.Log("Everyone");
yield return new WaitForSeconds(1);
}
IEnumerator ThreeMethod()
{
ButtonList.Add(3);
GameObject.Find("Green").GetComponent<Image>().color = Color.gray;
yield return new WaitForSeconds(1);
GameObject.Find("Green").GetComponent<Image>().color = Color.white;
Debug.Log("Everyone");
yield return new WaitForSeconds(1);
}
【问题讨论】:
-
immic 模仿了 1973 年的原始 Simon 游戏 - 给它一些信任! :)