Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

DeathZone Event

Discussion in 'Scripting' started by JMumford45, Nov 16, 2020.

  1. JMumford45

    JMumford45

    Joined:
    Jun 3, 2019
    Posts:
    14
    Hi everyone I'm trying to add an Event to my DeathZone but i don't really know how to tackle this my deathzone is activated with OnTriggerEnter with the player

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DeathZone : MonoBehaviour
    6. {
    7.     /*private void OnEnable()
    8.     {
    9.         EventManager.onEnter += EnterDeath;
    10.     }*/
    11.  
    12.     private void OnTriggerEnter2D(Collider2D collision)
    13.     {
    14.         Debug.Log(collision.name);
    15.         Debug.Log(gameObject.activeSelf);
    16.         if (collision.gameObject.tag == "Player")
    17.         {
    18.             Debug.Log("executes if statement");
    19.             collision.gameObject.SetActive(false);
    20.             Debug.Log(gameObject.activeSelf);
    21.             GameManager.gm.StartCoroutine(GameManager.gm.RespawnPlayer(collision.gameObject));
    22.         }
    23.     }
    24. }
     
  2. Sphinks

    Sphinks

    Joined:
    Apr 6, 2019
    Posts:
    267
    I tihnk the problem is, that you deactive your gameobject to early. Try to set the line:
    collision.gameObject.SetActive(false);

    as last line in your if statement
     
  3. JMumford45

    JMumford45

    Joined:
    Jun 3, 2019
    Posts:
    14
    thanks for the reply, my deathzone works as intended i just want to add it to the eventmanager as an event