Setting rotation when instatiating a object

This is my existing code for my random gen for trees and rocks but I want to make it so every object gets a random rotation and I cannot figure this out.


You’re already setting rotation while instantiating those objects. Quaternion.Identity (which means rotation at 0 x, 0 y and 0 z) is the rotation you’re setting all your instantiated objects to. So instead of Quaternion.Identity pass a different quaternion.

Use something like this:

//Random rotation on the Y axis, I'm assuming that's what you want but you could
//easily do this for the other axes as well.
var tree = Instantiate(Tree, new Vector3(bla, bla, bla), Quaternion.Euler(0,Random.Range(0,360f),0)); 

Hope this helps!

Note: On future posts, please, instead of taking a picture of the code, post the text right here using the code sample button. That way is a lot easier for people to help. Regards