I’m stuck!
I have a ball object that moves around. On top of that I have an emptyObject which is targeting the ball. Attached to the emptyObject is another object attached with a joint. I have a script in my ‘player control’ which destroys the ball. Now, I want it to destroy the gameObject and the other object attached to the ball. I have a an object that when the objects collide, they disspear/are killed. This is part of the script that destroys the ball in C#
void OnTriggerEnter(Collider other)
{
if (other.tag == "Destroy")
{
_GameManager.GetComponent<GameManager>().Death();
Destroy(gameObject);
I was thinking that I could associate a tag with the objects and to this script, like this, but it doesn’t seem to work…
void OnTriggerEnter(Collider other)
{
if (other.tag == "Destroy")
{
_GameManager.GetComponent<GameManager>().Death();
Destroy (GameObject.FindWithTag("Player"));
}
If this is not possible (although I’m sure it is), can these objects have their own Destroy/collision code? I really just wat to kill the whole collection of objects on impact with another.
I’m pretty new to this and not a coder by trade, so please be forgive the newbiness 
Thanks in advance for any ideas for this one.
Rich
Add game object variables for those two and destroy them as well
Or you could destroy based on tag, but not if you check the colliders tag
The way you did it is checking the collider objects tag and destroying it
If you find all gameobjects with the tag and destroy it should work
If you have a script attached to every GameObject that you want to destroy then you can also issue a ‘SendMessage’ command to all the GameObjects that you want to destroy on collision. Visit the SendMessage documentation in unity script reference to read more about it.
Could it be possible that GameObject.FindWithTag(“Player”) is returning NULL?
Here’s a general way to destroy other game objects that are associated with (in some custom way, other than being parented to) a main game object.
In your main object (your ball), you can allow attached objects to “register” themselves with it and when the main object is destroyed, it can call destroy on all attached objects as well.
private List<GameObject> attachedObjects = new List<GameObject>();
public void RegisterAttachedObject(GameObject go)
{
attachedObjects.Add(go);
}
void OnDestroy()
{
foreach(GameObject go in attachedObjects)
{
Destroy(go);
}
}
In the Start() of any of your attached objects, just call the myMainObjectReference.RegisterAttachedObject(gameObject);
and you should be good to go after that. Now, when your main object is destroyed, all attached objects will be destroyed too.