[英]how to delete a cloned prefab class in unity?
I used the code Destroy(), but when I check the program while it's still running, the the Object is still there. 我使用了代码Destroy(),但是当我在程序仍在运行时对其进行检查时,对象仍然存在。 Am I missing something?
我想念什么吗?
class: mobile
{
GameObject mobileObject;
SpriteRenderer mobileSR;
int height;
int width;
}
void Start()
{
mobile clone;
clone = Instantiate(mobile);
Destroy(clone); //object clone didn't delete :(
}
You're destroying your class instance. 您正在破坏您的类实例。 If you wanna destroy GameObject too, make your
mobileObject
property public and use Destroy(clone.mobileObject);
如果您也想销毁
mobileObject
,请公开您的mobileObject
属性并使用Destroy(clone.mobileObject);
Edit: Best way to delete your instance and destroy object is like this; 编辑:删除实例和销毁对象的最佳方法是这样的;
class: mobile
{
GameObject mobileObject;
SpriteRenderer mobileSR;
int height;
int width;
public void destroy(){
Destroy(mobileObject); //deletes GameObject
Destroy(this); //deletes instance of class
}
}
then; 然后;
void Start()
{
mobile clone;
clone = Instantiate(mobile);
clone.destroy();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.