统一 - 实例化的对立面 - 转变不破坏

时间:2017-05-28 14:57:25

标签: c# unity3d unity5

我试图在更新中破坏下面的prefab1(破坏它的游戏对象)但是我的游戏中的预制件没有被删除。 DESTROYING HOLE 1 GEMS调试下面出现在控制台和gameobject中,但是即使gemCount_Hole1小于1,宝石(预制精灵)也不会从我的游戏中删除。请帮忙

            if (gemCount_Hole1 < 1)
        {
            Debug.Log("DESTROYING HOLE 1 GEMS");
            if (prefab != null) Destroy(prefab.gameObject);
        }
        else
        {
            for (int i = 0; i < gemCount_Hole1; i++)
            {
                Instantiate(prefab, new Vector3((i + xPos_Hole1) * 2.0F, -14, 0), Quaternion.identity);
            }
        }

我创建了一个列表,但不知道如何编写destroy。以下是我将其编码为列表的方式

 private System.Collections.Generic.List<GameObject> list ; 
 void Start()
 {
  list  = new System.Collections.Generic.List<GameObject>();
 } 
 void Update()
 {
  for (int i = 0; i < gemCount_Hole1; i++)
  {
   list .Add( Instantiate(prefab, new Vector3((i + xPos_Hole1) * 2.0F, -14, 0), Quaternion.identity)) ;
  }
 }

1 个答案:

答案 0 :(得分:1)

您无法直接销毁预制件 当您将预制件实例化为GameObjects时,您必须将它们存储到Array GameObject []或List中,然后在销毁它时,在列表中找到它并从那里销毁它。

相关问题