Unity - 实例化的反面是什么 - 变换而不是破坏
Unity - Whats the Opposite of instantiate - Transform not destroying
我试图在更新中销毁下方的预制件 1(销毁其游戏对象),但预制件不会在我的游戏中被删除。下面的 DESTROYING HOLE 1 GEMS 调试出现在控制台中并且游戏对象被销毁,但是即使 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);
}
}
我创建了一个列表,但不知道如何编写销毁。这是我将其编码为列表的方式
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)) ;
}
}
您不能直接销毁预制件。
当您将预制件实例化为 GameObjects 时,您必须将它们存储到 Array GameObject[] 或 List 中,然后在销毁它时,在列表中找到它并从那里销毁它。
我试图在更新中销毁下方的预制件 1(销毁其游戏对象),但预制件不会在我的游戏中被删除。下面的 DESTROYING HOLE 1 GEMS 调试出现在控制台中并且游戏对象被销毁,但是即使 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);
}
}
我创建了一个列表,但不知道如何编写销毁。这是我将其编码为列表的方式
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)) ;
}
}
您不能直接销毁预制件。
当您将预制件实例化为 GameObjects 时,您必须将它们存储到 Array GameObject[] 或 List 中,然后在销毁它时,在列表中找到它并从那里销毁它。