I have a game object which has 10 child objects, which are all coins. I set up a killregion on the left of the screen that I want to use to destroy everything that touches it.
Here’s what I’m using for the KillRegion:
#pragma strict
function Start ()
{
}
function Update ()
{
}
function OnTriggerEnter (other : Collider)
{
Destroy(other.gameObject);
}
The individual coins are all objects with their own box colliders because I want the player to be able to collect them individually. The parent coin group object only has a transform component. The individual coins are all set to be triggers. I’ve read the information about Object.Destroy and I can’t come up with a solution that destroys the children and the parent. I’ve also tried making the Kill Region a trigger but that didn’t lead me anywhere promising yet. Any insight would be great! Thanks!
That seems to be deleting the parent, but I'm randomly getting this error regarding that function: NullReferenceException UnityEngine.Component.get_gameObject () KillRegion.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/KillRegion.js:16) I'm guessing because I'm destroying the parent and then the child objects have nothing to reference? Is there a more "right" way of doing this?
– imnickbI also tried adding a collider to the whole group of coins but then I needed to add a rigid body and set that in motion as well as the child coins and it just got messier and messier. If anyone has any other ideas I'd love to hear them. Thanks!
– imnickbThank you @EliteMossy - worked for me
– garthhumphreys