I created an infinte runner game.
I need to make random spawning obstacles ON 3D.
How do I randomly spawn prefabs on the X axis using a C# script?
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
Modified from the unity docs:
//creates a position between -10 to 10 on the x-axis float randomRange = Random.Range(-10.0f, 10.0f); Vector3 randomPosition = new Vector3(randomRange, 0, 0); var alexsObstacle = Instantiate( AlexsObstaclePrefab, randomPosition, Quaternion.identity);