Hello!
So i have this very simple “transform.Rotate(new Vector 3 (0, Rotation,0));” code inside Update that makes the object rotate. I want to add few more lines like this but with different values of Vector 3 and make Unity randomly select one of them if object is spawned . I guess it supposed to be pretty easy but it is not for me… Can anyone help?
You can use Random.Range(...)
to help generate random numbers for rotating. Range takes two parameters, a min and max. Generate three random values in this manner to populate a whole Vector3.
Use a switch statement along with Random.Range like so:
int randomXYZ = Random.Range(0, 3); // int random.range excludes the last number so it will go from 0 to 2
switch (randomXYZ)
{
case 0:
transform.Rotate(new Vector3(Rotation, 0, 0));
break;
case 1:
transform.Rotate(new Vector3(0, Rotation, 0));
break;
case 2:
transform.Rotate(new Vector3(0, 0, Rotation));
break;
}