I’m trying to change a function that uses a transform array into a function that uses a gameobject array. So I can modify the Gameobjects directly since transformArray.gameobject is read only. Except I’m not sure how to keep the functionality intact since the code will only accept a transform variable. Any idea if I can change this?
Original code
void FindGameObjectsChildrenByTag(string tag, ref Transform[] transformArray){
GameObject go = GameObject.FindGameObjectWithTag(tag);
if (go != null){
transformArray = go.GetComponentsInChildren<Transform>();
}
else if (Debug.isDebugBuild)
Debug.LogError(string.Format("No GameObject with tag {0} was found.", tag));
}
Modified Code
void FindGameObjectsChildrenByTag(string tag, ref Gameobject[] gameobjectArray){
GameObject go = GameObject.FindGameObjectWithTag(tag);
if (go != null){
gameobjectArray = go.GetComponentsInChildren<GameObject>();
}
else if (Debug.isDebugBuild)
Debug.LogError(string.Format("No GameObject with tag {0} was found.", tag));
}