This post is currently awaiting moderation. If you believe this to be in error, contact a system administrator.
Question by
SeanHerriott · May 04, 2019 at 07:11 PM ·
rotationinstantiaterandom
How can I Instantiate an object with a random y rotation but in 90 degree increments?
I am pretty much a complete noob at coding. I've setup a float[] with 0, 90, 180, and 270 but I can't figure out how to instantiate my tiles with the random y set to one of the above angles. Any help would be greatly appreciated.
Comment
Best Answer
Answer by Hellium · May 04, 2019 at 07:27 PM
Instantiate( prefab, position, Quaternion.Euler( 0, angles[ Random.Range( 0, angles.Length ) ], 0 ) );
Without the array:
Instantiate( prefab, position, Quaternion.Euler( 0, Random.Range( 0, 4 ) * 90, 0 ) );
Thank you so much. That worked a treat. It was wrecking my head! :)
Your answer
Follow this Question
Related Questions
How to spawn objects on a list of Transforms ? 2 Answers
Gameobjects spawn differently on client and host. 0 Answers
How to make another ground spawn beneath itself 1 Answer
Randomly Placing Prefabs on a Grid 0 Answers
Rotation of instantiated object 1 Answer