- Home /
Random number variable is shown twice
Hi,
Sorry for the newbie question. This silly thing just bugs me and I am confused why it happens. I have a variable which randomly picks a number between 1-10. When the game starts, it has to show me which number it picked. Each time I check the console and start the game, a random number is selected twice.
So when I start the game right now, my console gives me this:
gameMode:5 gameMode:8
How is this possible? Don't I execute this code just once?
static var gameMode : int;
function Start (){
gameMode = Random.Range(1, 10);
print ("Gamemode:" + gameMode);
}
Answer by derrtyones · Aug 29, 2012 at 11:22 AM
I only thought I had the script attached to the Player. But when I remove that script it's only executed once. Leaves me wondering which object holds this script as well. Any way to find out? Thanks for the solution, Piflik!
Your answer
![](https://koobas.hobune.stream/wayback/20220613080338im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making an Array of Animations Play at Random With No Repeats 3 Answers
Simple array an spawning question 6 Answers
Ball Bounce with Random Range 1 Answer