How to Destroy the instances of 2 gameObjects at the same time?

I have 2 game objects that will spawn continuously throughout the gameplay, the 2 game objects are elements of a spawner game object that I created. While I can destroy the lightning, I cannot destroy the cloud. I have 2 scripts attached to the prefabs of the 2 game object, this is attached to the lightning prefab:

using UnityEngine;
using System.Collections;

public class lightningKills : MonoBehaviour {

    private Collision2D c;
    public float howHeavy;
    public bool isDestroyed = false;

    void Start()
    {
        howHeavy = GetComponent<Rigidbody2D>().mass;
    }

    void OnCollisionEnter2D(Collision2D c)
    {
        switch(c.gameObject.tag)  
        
        {
            case "Player":
                Debug.Log("YOU DEAD!");

                //Kills the Player!
                cuteCube.SharedInstance.Death();
                Destroy(gameObject);
                isDestroyed = true;
                Debug.Log("cubeCube is DEAD!");
                break;

            case "Background":
                if (gameObject.name == "lightning(Clone)")
                {
                    Destroy(gameObject);
                    isDestroyed = true;
                    Debug.Log("Destroyed!");
                }               
                break;
            default:
                Destroy(gameObject);
                if (gameObject.name == "lightning(Clone)")
                {
                    Destroy(gameObject);
                    isDestroyed = true;
                    Debug.Log("Destroyed!");
                }
                break;

        }
    }

}

This is attached to the cloud prefab:

using UnityEngine;
using System.Collections;

public class DestroyIt : MonoBehaviour
{ 
    void Awake()
    {
        GameObject getLightning = GameObject.Find("lightning");
        lightningKills theLightning = getLightning.GetComponent<lightningKills>();

        if (theLightning.isDestroyed)
        {
            Destroy(gameObject);
            Debug.Log("Destroyed this freaking cloud");
        }
    }
}

Basically I am trying to access the boolean isDestroyed and when it is true, it will trigger the cloud instance to be destroyed. But it doesnt work!!! HELP!

You don’t really want to be checking variables on an object which might be destroyed (i.e. there is potential for theLightning to be null, meaning that checking theLightning.isDestroyed could give you a Null reference error.

If you want something destroyed immediately, you can Use DestroyImmediate, but it’s not recommended for performance reasons.

What you could do is simply check if theLightning == null, then destroy the cloud object. Alternatively you could use the MonoBehaviour OnDestroy() calls from one to start the destruction of the other.

Also note that you are checking if theLightning.isDestroyed in the Awake function of the cloud object. This seems a little odd unless you’re trying to destroy the object before it’s ever seen or used (or I may not understand what you’re trying to achieve).