2D Shooter: Destroying a Parent Object


In the past we figured out how to destroy objects, but what happens if the object is attached to a parent object, and both get created when its spawned? Well, the child object would be destroyed, but the parent would still remain. To keep our hierarchy tidy, we need to remove all family members.

Objective: Be able to destroy the tripleshot object when the lasers go past the playable area.

All we need to do is add a bit of code to our laser script, as the basic laser is the building block to our triple shot. A extra if statement in the code where we destroy the laser should be all that we need.

This code is just checking that the object has a parent, and if it does that parent object get destroyed too.



Sabrina Windsor

Currently learning to code with the help of GamedevHQ in order to someday my my game ideas come to life!