- Home /
Not able to set explosion.SetActive(true) on player destroy
I seem to be having an issue getting the bigExplosionEffect to set active when player is destroyed... What is it that I'm doing wrong? Thanks.
Here is the DestroyController Class...
public class DestroyController : MonoBehaviour {
public GameObject theCanvas;
public DeathCanvas canvas;
public GameObject bigExplosionEffect;
// Use this for initialization
void Start () {
canvas = GetComponent<DeathCanvas>();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
Explosion.playerHasDied = true;
DestroyObject(other.gameObject);
DeathCanvas.PlayerIsKilled = true;
}
}
}
Here is the Explosion Class...
public class Explosion : MonoBehaviour {
public GameObject bigExplosionEffect;
public GameObject player;
public static bool playerHasDied = false;
// Use this for initialization
void Start () {
bigExplosionEffect = GameObject.Find("BigExplosionEffect");
bigExplosionEffect.SetActive (false);
player = GameObject.FindGameObjectWithTag("Player");
}
// Update is called once per frame
void Update () {
if (playerHasDied = false) {
Debug.Log ("EXPLODE AND DIE!");
bigExplosionEffect.SetActive (true);
}
}
}
Comment
Answer by Yoshinator2 · Jul 31, 2017 at 02:13 PM
Your if statement in the Explosion class has a few errors.
You have to use two equals signs if you are comparing two parameters. You are using one, which modifies the parameter instead. Also, you need to change the false to true in the if statement.
if (playerHasDied == true) {
Debug.Log ("EXPLODE AND DIE!");
bigExplosionEffect.SetActive (true);
}
If this solved your problem, please accept my answer :)