I am very new to Unity and to C# so I am sure there is a million things wrong with this code but I am hoping one of you will be able to get me through the error I am seeing. Ok here goes.
I have a prefab that contains 1 panel, 6 buttons, 2 text object and an image (10 total objects). When these object are loaded on the scene some of them are active and other are not (setactive = t/f). Because of the objects being inactive I can not use the GameObject.Find function to get a handle to them. So i decided to create a multidimensional array to store these object so I can reference them later.
I am getting the follow error:
ArgumentException: GetComponent requires that the requested component ‘GameObject’ derives from MonoBehaviour or Component or is an interface.
UnityEngine.GameObject.GetComponentsInChildren[GameObject] (Boolean includeInactive)
```csharp
*using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
public class EnumPanes : MonoBehaviour {
public GameObject objMinerPanes;
public GameObject[,] objPaneIndex;
public void EnumMinerPanes()
{
GameObject[] objMyChildren;
int rows;
int cols = 10;
int i = 0;
//Find all panel objects with tag "MinerPanes"
objMinerPanes = GameObject.FindGameObjectsWithTag ("MinerPanes");
rows = objMinerPanes.Length;
GameObject[,] objPaneIndex = new GameObject[rows, cols];
//Add panel object to the 1st dimension of the array
foreach (GameObject myPane in objMinerPanes)
{
objPaneIndex [i, 0] = myPane;
objMyChildren = myPane.GetComponentsInChildren<GameObject> ();
// load 1-9 with the right ojbjects
foreach (GameObject kids in objMyChildren)
{
switch (kids.tag)
{
case "MinerLevelUp":
objPaneIndex [i, 1] = kids;
break;
case "MinerImg":
objPaneIndex [i, 2] = kids;
break;
case "MinerLevel":
objPaneIndex [i, 3] = kids;
break;
case "MinerName":
objPaneIndex [i, 4] = kids;
break;
case "MinerSkill1":
objPaneIndex [i, 5] = kids;
break;
case "MinerSkill2":
objPaneIndex [i, 6] = kids;
break;
case "MinerSkill3":
objPaneIndex [i, 7] = kids;
break;
case "MinerSkill4":
objPaneIndex [i, 8] = kids;
break;
case "MinerSkill5":
objPaneIndex [i, 9] = kids;
break;
}
}
i++;
}
Debug.Log(objPaneIndex[0,1].name);
Debug.Log(objPaneIndex[1,2].name);
Debug.Log(objPaneIndex[2,3].name);
Debug.Log(objPaneIndex[3,4].name);
Debug.Log(objPaneIndex[4,5].name);
}
}*
```
Thanks in advance for the help.