How might I return all the gameobjects, and their children into an array?
This is so I might loop through and apply a global materials change.
Tagging gameobjects is out of the question unless there is a way to apply a tag to all the children in the gameobject (So i can reference them individually)
Have you tried:
var gameObjs : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];
Scene scene = SceneManager.GetActiveScene();
GameObject rootObjects = scene.GetRootGameObjects();
Hi,
Let’s say you want to access only the gameobjects that you have in your scrpit (e.g script name is DemoScript). To access only these game objects, try this:
object obj = GameObject.FindObjectsofType(typeof(DemoScript));
foreach(object o in obj)
{
//do something
}
Hope this helps.
Hi Tomleung,
Sure. You can try this.
object obj = GameObject.FindObjectsofType(typeof(DemoScript));
for(int i=0;i