[英]Weird Unity prefab behaviour?
问题似乎是您在实例化 BigRock 时没有更改引用。 BigRock 作为预制件,与生成的 GameObject 不同。 您应该有第二个变量指代新生成的岩石。
请记住,场景中不存在第一个,因此您应该保存在场景中实例化的那个。
// This will be the reference to the PREFAB
public GameObject big_rock;
// This will be the referenced to the new spawned gameobject
private GameObject spawned_big_rock;
private void SpawnRock()
{
GameObject gameobjectThatWeJustSpawned = Instantiate(big_rock);
// We set the reference to the one that was spawned
spawned_big_rock = gameobjectThatWeJustSpawned;
}
public void DestroyRock()
{
// We destroy the one that was spawned
Destroy(spawned_big_rock);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.