So, I cannot implicitly convert type object[] to UnityEngine.GameObject[]. But why? As far I know, are all types a inheritanced types of object. So, for my logic, I could put a GameObject array in a object array. That's why, this should work:
spawnedObjects = FindObjectOfType<Tools> ().AddObjectToArray (spawnedObjects, go);
//
public object[] AddObjectToArray(object[] _array, object _toAdd){
if (_array.GetType() == _toAdd.GetType()) {
object[] a = new object[_array.Length + 1];
a = _array;
a [a.Length] = _toAdd;
return a;
} else {
Debug.LogWarning ("The object that should be added to the array have to be the same type as the arrays type. Initially array was retuned!");
return _array;
}
}
But yeah, it won't do
object[]is not the same as Unity's representation ofUnityEngine.GameObject[]. You make it sound like you are castingobject[]into something more specific:UnityEngine.GameObject[]\$\endgroup\$