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!