How i Do random rotation?

I have an object that makes instances , it works very well. But i would to put random rotation on created instances. This is my code for instances :

Vector3 SpawnPosition = new Vector3(0, 0, 62); // Position of the spawning point
SpawnPosition = this.transform.position + Random.onUnitSphere * RangoCreacion; // How will create objects spawn position
SpawnPosition = new Vector3(SpawnPosition.x, SpawnPosition.y, 0); // For spawning objects on axis Y and x
Copy = Instantiate(pieces[UnityEngine.Random.Range(0, 5)], SpawnPosition, Quaternion.identity); // For copying objects of rack and the position from they will begin

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

You may edit your post above.

Are you perhaps looking for the Quaterion.Euler() factory function? You could supply it with randomly generated values for heading, then supply it instead of Quaterion.identity when you Instantiate.

1 Like