我的问题是我的原始预制件没有用其所有组件进行实例化。这是因为在某些事件之后,这些对象会被破坏。但是当我实例化预制件时,我希望它再次拥有它的所有对象。有谁知道我能做些什么呢?
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.name.Contains ("Player"))
{
if(count == 0){
Debug.Log("Enemy Collision");
Instantiate(ground,new Vector3(distance, 0, 0), Quaternion.identity);
Destroy(ground);
distance = distance+ 40.31f;
count=1;
}
else{
Debug.Log("Enemy Collision");
Instantiate(ground,new Vector3(distance, 0, 0), Quaternion.identity);
Destroy(ground);
distance = distance + 40.31f;
}
}
}
答案 0 :(得分:0)
不要销毁预制件 - 只需销毁新实例化的对象(假设这是你的意图):
var groundToBeDestroyed = Instantiate(ground, new Vector3(distance, 0, 0), Quaternion.identity);
Destroy(groundToBeDestroyed);