I found the solution for my question, thereby I'll ask my question, maybe it will be helpful for someone else:
unityGameObjects.Add(GameObject.Find(unityObject.Value));
Pergunta
I have gameObjects and I need to put them to the list, something like that:
List<GameObject> unityGameObjects = new List<GameObject>();
Solução 4
I found the solution for my question, thereby I'll ask my question, maybe it will be helpful for someone else:
unityGameObjects.Add(GameObject.Find(unityObject.Value));
Outras dicas
You first create your list.
List<GameObject> unityGameObjects = new List<GameObject>();
You need to have a reference to the GameObject you which to add to the list. You can do this by looking for the GameObject or by creating a new instances of it.
GameObject g = GameObject.Find("NameOfGameObject");
unityGameObjects.Add(g);
You can't call new
on GameObjects because they are MonoBehaviours but you can instantiate them from a prefab.
GameObject g = Instantiate(prefab);
unityGameObjects.Add(g);
unityGameObjects.Add(new GameObject());
MyList.AddRange( new List<GameObject> { new GameObject { name = "Frank", tag = "3" ,layer= 2, active = isActiveAndEnabled, hideFlags = HideFlags.HideInHierarchy, isStatic = false },
new GameObject { name = "Jill", tag = "3" },
new GameObject { name = "Dave", tag = "5" },
new GameObject { name = "Jack", tag = "8" },
new GameObject { name = "Judith", tag = "12" },
new GameObject { name = "Robert", tag = "14" },
new GameObject { name = "Adam", tag = "1" } } );