- Home /
destroy parent of script
I am trying to make it so when you click on a cube it removes it self...
at first I had
function OnMouseDown() {
Destroy(this);
}
But that was just deleteing the script so than I tried
function OnMouseDown() {
Destroy(this.transform.parent.gameObject);
}
And nothing really happens
Help please?
Comment
Best Answer
Answer by Muzz5 · May 30, 2011 at 05:19 AM
function OnMouseDown(){
Destroy(gameObject);
}
Easy! ( I asked the same question a few months back).
Destroy() just marks objects to be destroyed at the end of the frame, so it is not as dangerous as it seems to destroy yourself.
Your answer
Follow this Question
Related Questions
Destroying an object from its script. 1 Answer
Changing the parent of an object in a script 2 Answers
Transform.Parent Not Working 1 Answer
transform.parent can't go with gameObject.find 3 Answers
Script to destroy object 1 Answer