Hi all, quick question about "FindObjectsOfType"...right now the way it's being used returns all objects of type T[] in the scene:
public GameObject myGO;
void Awake(){
foreach(GameObject go in FinObjectsOfType(typeof(GameObject)) as GameObject[])
{
if (go.name == "The Name I'm Looking For")
{
myGO = go;
}
}
}
Returning all GameObjects in the scene when I'm only looking for only 1 object, which I know is a child of another GameObject, is a huge waste of time. So is there a way to do this:
public GameObject myGO;
private GameObject playerObj;
void Awake(){
playerObj = GameObject.FindWithTag("Player");
foreach(GameObject go in playerObj.FinObjectsOfType(typeof(GameObject)) as GameObject[])
{
if (go.name == "The Name I'm Looking For")
{
myGO = go;
}
}
}
That way "FindObjectsOfType" only looks in the "playerObj" GameObject for objects of type "GameObject" instead of looking through the entire scene.
Also, is "FindObjectsOfType" faster the "GameObject.Find" ?
Thx for any help in advance! Stephane