0
\$\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\$
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\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.