1 回答
TA贡献1891条经验 获得超3个赞
我不确定这是否会解决您的问题,但这是生成随机顺序列表的更好方法:
public class MyClass {
private List<int> PreList = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
private List<int> ButtonList = new List<int>();
private List<int> UserList = new List<int>();
void Randomizer() {
while (PreList.Count > 0 ) {
var idx = UnityEngine.Random.Range(0, PreList.Count); // Randomly select from remaining items
var value = PreList[idx]; // Get item value
PreList.RemoveAt(idx); // Remove item from future options
ButtonList.Add(value); // Add to end of 'randomised' list
}
foreach (var value in ButtonList) {
DoSomethingWith(value);
}
}
void DoSomethingWith(int value) {
switch(value) {
case 1: OneMethod(); break;
case 2: TwoMethod(); break;
case 3: ThreeMethod(); break;
case 4: FourMethod(); break;
case 5: FiveMethod(); break;
case 6: SixMethod(); break;
case 7: SevenMethod(); break;
case 8: EightMethod(); break;
case 9: NineMethod(); break;
}
}
}
编辑:添加示例使用 DoSomething()
- 1 回答
- 0 关注
- 146 浏览
添加回答
举报