Search Unity

How to Destroy Parent Object

Discussion in 'Scripting' started by Kaito Henry, Nov 22, 2014.

  1. Kaito Henry

    Kaito Henry

    Joined:
    Nov 3, 2014
    Posts:
    1
    I'm facing the problem that i wish to destroy a parent object but i couldn't do so.

    i wish to destroy User01 while bullet hit any of these child.

    My code was as below.

    JS:

    function OnControllerColliderHit(col:ControllerColliderHit){

    if(col.gameObject.tag =="Bullet"){

    Destroy(col.transform.parent.gameObject);

    }
    }

    C#:

    public class PlayerDoe : MonoBehaviour {

    privateGameObject par;

    // Use this for initializationvoidStart(){

    par = transform.parent.gameObject;}

    // Update is called once per framevoidUpdate(){

    }

    voidOnCollisionHit(Collision col){

    if(col.gameObject.tag =="Bullet"){Destroy(par);}}
    }
     
  2. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    Get a piercing or tattoo, that'll destroy 'em.
     
    Marble likes this.
  3. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Last edited: Nov 22, 2014