- Home /
Question by
vincentlindell · Mar 15, 2019 at 04:57 PM ·
randomstatecall
Call Random State
Im Pretty new to Unity and making games and im just wondering a thing. If I want the player to spawn on either PositionX or PositionY, How should I do?
Script:
Public Transform Player;
Public Transform SpawnPositionX;
Public Transform SpawnPositionY;
If ( 1 > 0)
{
Player.Position = SpawnPositionX;
Player.Position = SpawnPositionY;
//Here I want the player to spawn on one of the positions (Random);
}
Comment
Answer by Tsaras · Mar 16, 2019 at 07:40 AM
You would do that by using Random.Range.
Public Transform Player;
Public Transform SpawnPositionX;
Public Transform SpawnPositionY;
If ( 1 > 0) //what is the purpose of this?
{
int rnd = Random.Range(0,1);
if (rnd==0){
Player.transform.position = SpawnPositionX;
} else {
Player.transform.position = SpawnPositionY;
}
}