Player destroyes when colliding with colliders.

Hey, I’m making a game, and whenever I touch a box collider or a circle collider etc. Here’s all my code’s where I I use the destroy thing.

    void OnTriggerEnter2D (Collider2D hitInfo)
    {
        if (hitInfo.gameObject.tag.Equals ("Enemy"));
        {
            Destroy (hitInfo.gameObject);
            Destroy (gameObject);
        }

and

    void TriggerEnter2D (Collider col)
    {
        if (col.gameObject.tag.Equals ("Player"))
        {
            Die.Play();
            Destroy (col.gameObject);
        }
        if (col.gameObject.tag.Equals ("Bullet"));
        {
            PlayerDie.Play();
            Destroy (gameObject);

and

    void OnTriggerEnter2D (Collider2D hitInfo)
        {
        if (hitInfo.gameObject.tag.Equals ("Enemy"));
        {
            Destroy (gameObject);

I don’t know if the code’s help, but if anyone know’s how to fix please reply. Thank you, much appreciated. :slight_smile:

You’re pretty explicitly destroying the player in your second snippet on line 6… maybe don’t do that? You might also be destroying the player in your first snippet on line 6 but it’s impossible to tell without more context (like which script this is contained in and which GameObject the script is attached to).

1 Like