I want to use Random.Range to select an element of an array arr(“list1”,“list2”) so that I can load objects in the order specified in arr(“listX”). Here is my code, it works so that I am randomly selection one of the strings from arr but how do I then access the variable with the name specified in that string.
var presentationLists = new Array("list1","list2");
var list1= new Array("Obj1","Obj2");
var list2= new Array("Obj2","Obj1");
var pres_list = new Array();
var viewTime:int=3;
var Obj1:GameObject;
var Obj2:GameObject;
var tmpObject:GameObject;
function Start () {
var r = Random.Range(0,presentationLists.length-1);
var listNum=presentationLists[r];
pres_list = //this is what I'm trying to get. How do I get the array based on the string in listNum?
for(var n = 0; n < pres_list.length; n++){
var tmpString:String = pres_list[n];
tmpObject=GameObject.Find(tmpString);
tmpObject.transform.position = Vector3(1013,499,1285);
yield WaitForSeconds(viewTime);
tmpObject.transform.position = Vector3(0,0,0);
}
}