Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Do you mean you want to do this in code, or in the editor? – user744 May 2 '11 at 13:49
up vote 5 down vote accepted

To loop over all GameObjects, use the following code:


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


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

Also see the manual for FindObjectsOfType.

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.