美好的一天,我的 Unity 游戏中有一个脚本,它创建一个列表并将其数字顺序随机化,然后将值传递给另一个列表以检查一些特定属性,这是代码:
// Use this for initialization
private List<int> PreList = new List<int>();
private List<int> ButtonList = new List<int>();
private List<int> UserList = new List<int>();
private System.Random Rnd = new System.Random();
void Randomizer()
{
PreList.Add(1);
PreList.Add(2);
PreList.Add(3);
PreList.Add(4);
PreList.Add(5);
PreList.Add(6);
PreList.Add(7);
PreList.Add(8);
PreList.Add(9);
PreList = PreList.OrderBy(C => Rnd.Next()).ToList();
foreach (int Number in PreList)
{
Debug.Log(Number);
Debug.Log(ButtonList.Count);
if (Number == 1)
{
OneMethod();
}
else if (Number == 2)
{
TwoMethod();
}
else if (Number == 3)
{
ThreeMethod();
}
else if (Number == 4)
{
FourMethod();
}
else if (Number == 5)
{
FiveMethod();
}
else if (Number == 6)
{
SixMethod();
}
else if (Number == 7)
{
SevenMethod();
}
else if (Number == 8)
{
EightMethod();
}
else if (Number == 9)
{
NineMethod();
}
}
}
void OneMethod()
{
ButtonList.Add(1);
GameObject RedButton = GameObject.Find("Red");
//There are 8 methods just like this, but it variates some stuff like the name and the number, all of these add numbers to ButtonList
}
此时,输出控制台只是说 ButtonList 的计数是 9,但是,如果我放一个 if 来检查它,它永远不会将值设为 true,就像它不执行方法并且 ifs 永远不会运行,但是,你知道为什么吗?
万千封印
相关分类