# Selecting all GameObjects in Unity

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?

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

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.

• 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 '16 at 15:42