Добрый день, у меня есть скрипт в моей игре 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 никогда не запускается, но у вас есть идеи почему?