I have a script that destroys the gameobject the script is in when a variable reaches 0. I really need to destroy the parent though.
So Object A is inside of Object B. The script is inside of Object A. I need to destroy Object B. Can anyone help me out?
I haven’t tested this code but I believe you should be able to do the following
GameObject ObjectB = ObjectA.transform.parent.gameObject;
Then you can destroy ObjectB
Create a variable and give it to eat to your script !
In your script :
var myObjectToDelete:GameObject;
function Update()
{
Destroy(myObjectToDelete);
}
Don’t forget to put your game object in the inspector of the script. This should work.
Very important : put the destroy line at the very end, if you do something after, there will be errors …