5
\$\begingroup\$

I want to rotate all my GameObjects by 90 degrees. To do that I need to select all my GameObjects, how can I do so?

\$\endgroup\$
  • \$\begingroup\$ Do you mean you want to do this in code, or in the editor? \$\endgroup\$ – user744 May 2 '11 at 13:49
6
\$\begingroup\$

To loop over all GameObjects, use the following code:

JavaScript:

for(var gameObj : GameObject in GameObject.FindObjectsOfType(GameObject))
{
    // modify gameObj.transform.rotation
}

C#:

foreach(GameObject gameObj in GameObject.FindObjectsOfType<GameObject>())
{
    // modify gameObj.transform.rotation
}

Also see the manual for FindObjectsOfType.

\$\endgroup\$
  • 1
    \$\begingroup\$ FindObjectsOfType doesn't have a generic version, as far as I can tell. So you have to do FindObjectsOfType( typeof( GameObject ) ) as GameObject[]. \$\endgroup\$ – Tetrad May 2 '11 at 16:54
  • \$\begingroup\$ Good to know; I'm not at a computer with Unity to test it. \$\endgroup\$ – Ricket May 2 '11 at 17:45
  • \$\begingroup\$ It may just be a small micro-optimization, but I'd probably use a plain for loop over a foreach loop. \$\endgroup\$ – Ethan Bierlein Apr 25 '16 at 15:42

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.