How do I Destroy a Child after Instantiating it?

So, I’m making this game and my player has to pull out a gun and shoot a bullet. To do so, I Instantiated the gun as my Player’s Child, but now I want it to disappear, but when I try to Destroy it by code it simply destroys my Player too T-T.

I’m currently using a code like this:

private GameObject Gun; void Start() { Destroy(gameObject,1); }

I’m new to Unity and programming, so if you guys could post the code it would be really helpful :slight_smile:

Hi mate I’m not exactly sure how your script is working, but you could try passing the Gun variable to the Destroy method e.g Destroy(Gun, 1);
If the Gun gameObject isn’t right, then you can find the correct gameObject by doing the following:

GameObject.Find("NameOfGameObjectInHierarchy"); //This will search your whole scene


transform.Find("NameOfTransformInHierarchy"); //This will search just the children of your current transform

Another way you might want to do it, is to just disable the renderer the gun (Depending on if you truly want the gun to be destroyed or hidden when swapped to a secondary weapon for example)

Hope this helps :slight_smile: