- Home /
How to randomize the correct choice
I'll explain a little better. I'm making a text style game and what I want is for there to be a random, "right" choice. At the end, there are three doors and only one is the way out. I want the correct choice to change every playthrough. So it's not the same door every time and it requires a little luck on the players part. I'm new to Unity3d but tried every way that I thought would work, but with no luck. So any help would be appreciated! Thanks. :D
Answer by dr3th · Apr 02, 2015 at 06:51 PM
You need to call a Random number generator in your code. That generates a random number.
In your case... 1 2 or 3.
Answer by kingcoyote · Apr 02, 2015 at 07:02 PM
Use Random.Range. Just note that the range is min [inclusive] to max [exclusive]. So to get a 1, 2 or 3, you would set min to 1 and max to 4.
int correctDoor = Random.Range(1, 4);
Your answer
![](https://koobas.hobune.stream/wayback/20220613191929im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
v.important : Choose one from functions to execute !! 1 Answer
Call a function multiple times 2 Answers
Function action applies to every object that have script with that function on it. Help please 1 Answer
Can you make an array of functions? 2 Answers
How to use a function from another script inside of the Invoke () class? 2 Answers