I have a GameObject and I tried to add value to it with Add(), but it says " a definition for Array' and no extension method
Array’ of type `UnityEngine.GameObject’ could be found". How do I do it?
Arrays are fixed size at creation, you might wanna use a List. But if you wanna stick with arrays:
Assuming you’re using C#, here’s a function I wrote awhile back that lets you add a GameObject to a GameObject array. You pass in the original array and the gameobject, and it returns a new array with your gameobject added to it.
//adds GameObject Obj to array Array
public static GameObject[] AddToGameObjectArray(GameObject[] Array,GameObject Obj) {
GameObject[] NewArray = new GameObject[Array.Length + 1];
for (int i = 0; i <= Array.Length; i++) {
if (i == Array.Length)
NewArray *= Obj;*
-
else*
NewArray = Array*;*
* }*
* return NewArray;*
* }*