- Home /
Question by
ergiomarxD · Oct 23, 2014 at 05:37 AM ·
buttonrandomarraylist
How could I show buttons if I am using array list?
I'm trying to make a quiz and I uses arraylist for random output of questions. I want to show buttons that will serve as the choices for my Questions how could I possibly do it? here is my code. Thank you!
void Start () { randomGen (); }
void randomGen(){
ArrayList questionlist = new ArrayList ();
ArrayList choice1 = new ArrayList ();
ArrayList choice2 = new ArrayList ();
ArrayList calledCounters = new ArrayList ();
string[] questions = {"1","2","3","4","5","6","7","8","9","10"};
//string[] choice = {"A.Tinapa","B.Daing","C.Kangkong"};
//[] choices = {"A.kamote","B.kaldereta","C.suman"};
int counter = 0;
do{
int x= Random.Range(0,questions.Length-1);
if(!isExisting(x,calledCounters)){
calledCounters.Add(x);
questionlist.Add(questions[x]);
//choice1.Add (choice[x]);
//choice2.Add(choices[x]);
Debug.Log (x);
Debug.Log(questionlist[counter]);
Debug.Log(choice1[counter]);
Debug.Log(choice2[counter]);
counter++;
}
}while(counter<=2);
}
bool isExisting(int y, ArrayList x){
bool status = false;
for (int g=0; g<x.Count; g++) {
if (x.Contains (y)) {
status = true;
break;
}
}
return status;
}
// Update is called once per frame
void Update () {
}
Comment
You don't. Array list is an old class that should not be used anymore. It's only in the language still for back comparability. Use a generic list ins$$anonymous$$d. It's faster, does not require casting, type safe and has more features then the array list.
Your answer
