system
1
Hi there!
I’ve found for a long time and I didn’t find anything!
What I need is to pick up randomly a “name” from an array:
var NameArray : String;
NameArray[0] = "Name";
NameArray[1] = "Name";
NameArray[2] = "Name";
NameArray[3] = "Name";
How can I pick a name randomly from that array? Please, help!!
chosenName = NameArray[Random.Range(0, NameArray.length)];
EDIT :
Are you sure ?
make a new scene and a new script. attach the script to the camera, then copy and paste this into the script :
#pragma strict
var NameArray : String[] = ["Name 00", "Name 11", "Name 22", "Name 33"];
var chosenName : String;
function ChooseName()
{
chosenName = NameArray[Random.Range(0, NameArray.length)];
Debug.Log("chosenName " + chosenName);
}
function OnGUI()
{
if (GUI.Button(Rect(10, 10, 100, 35), "random")) {ChooseName() ;}
GUI.Box (Rect(120, 10, 100, 35), "" + chosenName);
}
system
3
Thanks for your answer!
I already did that, but chosenName is going to be a int. And what I need is the String that number has in the Array!
Thanks again!