- Home /
random range for gui button
how can i make the cardlist.cardList be a random number/card?
here's my code var cardlist; var tableTracker; cardlist = GameObject.FindWithTag("MainCamera").GetComponent("cardListing"); tableTracker = GameObject.FindWithTag("MainCamera").GetComponent("TableCardTracker"); var totalCardsInStack = 54; function OnGUI () { GUI.BeginGroup (new Rect (Screen.width / 2 - 400, Screen.height / 2 - 300, 800, 600)); for(var i :int = 0;i <= 2; i++) { totalCardsInStack = GUI.Button(Rect(100*i,10,100,150),cardlist.cardList[i]); if (cardlist.cardList[i]) {
}
}
GUI.EndGroup ();
}
Answer by rutter · Mar 24, 2012 at 06:12 PM
You can use `Random.Range()` to produce a random number between two values.
If you're trying to grab a random list element, you'll probably want a number n
between 0 and the list's length so that you can grab list[n]
.
Your answer
![](https://koobas.hobune.stream/wayback/20220613065508im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
C# Random Number on GUIButton click without updating every frame 0 Answers
triggering random animations with gui 1 Answer
GUISkin breakages 2 Answers
Smooth Random.Range 2 Answers
Make a Button out of a Textured Plane 2 Answers