C# Function Transform to Gameobject Convert

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));
	}

A GameObject is not a component. The easiest solution is to go back to your original code. Then if you need to access to the game object, just use:

transformArray*.gameObject*

You could first get a Transform array, and then build a GameObject array:
void FindGameObjectsChildrenByTag(string tag, ref Gameobject[] gameobjectArray){
GameObject go = GameObject.FindGameObjectWithTag(tag);
if (go != null){
Transform[] transformAraray = go.GetComponentsInChildren();
}
else if (Debug.isDebugBuild)
Debug.LogError(string.Format(“No GameObject with tag {0} was found.”, tag));
gameobjectArray = new GameObject[transformArray.Length];
for (int i = 0; i < transformArray.Length; i++)
gameobjectArray = transformArray*.gameObject;*
}
Or if you want to do it with simpler code, take a look at LinQ:
[unitygems.com - unitygems Resources and Information.][1]

_*[1]: unitygems.com