我有gameObjects,我需要把它们放到列表中,类似的东西:
List<GameObject> unityGameObjects = new List<GameObject>();
答案 0 :(得分:1)
unityGameObjects.Add(new GameObject());
答案 1 :(得分:1)
首先创建列表。
List<GameObject> unityGameObjects = new List<GameObject>();
您需要引用要添加到列表中的GameObject。您可以通过查找GameObject或创建它的新实例来完成此操作。
GameObject g = GameObject.Find("NameOfGameObject");
unityGameObjects.Add(g);
您无法在GameObjects上调用new
,因为它们是MonoBehaviours,但您可以从预制件中实例化它们。
GameObject g = Instantiate(prefab);
unityGameObjects.Add(g);
答案 2 :(得分:0)
我找到了我的问题的解决方案,因此我会问我的问题,也许这对其他人有帮助:
unityGameObjects.Add(GameObject.Find(unityObject.Value));
答案 3 :(得分:0)
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" } } );