【发布时间】:2013-07-27 13:58:54
【问题描述】:
如何在不得到相同值的情况下随机化这组数组?我不知道我做得对不对。它如何识别变化时的价值?
function Start ()
{
if(MasterVar.quiz<10)
{
var englishLecture = [
["Word that tells us about an action","Verb","Noun","Pronoun","a","0"],
["Name of person, place or things","Verb","Noun","Cute","b","0"],
["Select the noun","Swim","Shout","Joe","c","0"],
["There __ a cat","is","was","can","a","0"],
["You __ go home now","can","open","was","a","0"],
["She ___ her breakfast","ate","play","sleep","a","0"],
["Select the verb","John","is","table","b","0"],
["We ___ planning to go to the movies tonight","were","could","can","b","0"],
["What ____ that noise?","Were","Was","Can","b","0"],
["What ___ your name?","are","can","is","c","0"]
];
index = Random.Range(0,englishLecture.length);
while(englishLecture[index][5] == "1")
{
index = Random.Range(0,englishLecture.length);
}
englishLecture[index][5] == "1";
TextGUI = GameObject.FindGameObjectWithTag("Question");
TextGUI.GetComponent(GUIText).text = englishLecture[index][0];
sel1 = englishLecture[index][1];
sel2 = englishLecture[index][2];
sel3 = englishLecture[index][3];
rightAns = englishLecture[index][4];
}
else if(MasterVar.quiz>=10)
{
Application.LoadLevel("Score");
}
}
【问题讨论】:
-
你应该缩进代码sn-p,并有更好的标题,并为Unity和使用的语言添加标签......
-
您好,欢迎来到 Stack Overflow;这不是 100% 清楚你在问什么,记住我们不知道你的代码库。用简单的英语来说,你到底想达到什么目的?
-
或者你可以这样做@hyde;你有代表和语言在问题中......很高兴对新人很好。
-
如果数组索引已被选取,我正在尝试将值从 0 更改为 1,而 [index][5] == 0 的值将继续,但如果它相等到 1 它必须再次随机化才能选择另一个索引
-
感谢您的编辑
标签: arrays unity3d unityscript