-2
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

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);
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .