I need to know how to make it so that one of the players randomly gets selected to be the killer when the timer ends. I have the timer worked out but how do I randomly select one of the players, if they get to chose their names when the join a server. Should I create a variable for each player based on their IP, or is there a better way?
1 Answer
1Cool. If you need to select a value from a range, just do (something like) this:
public static int ChooseAtRandom(object[] array)
{
return Random.Range(0, array.Length);
}
Or:
public static int ChooseAtRandom(int min, int max)
{
return Random.Range(min, max);
}
I went ahead and made this an answer so that the question can be closed out if the OP wants to.
– iwaldrop
Assuming there are only two players, the following works like a coin flip. public static int FlipCoin() { return Random.value > 0.5f ? 1 : 0; }
– iwaldropOk, Thanks iwaldrop I'll use this in testing and later use more advanced methods.
– UFO_Pirate