[Tip] The Top Shedder destroying Enemies

Just a tip if anyone else had this.

I had a bug that was bugging me. Ohhh that was bad…

The Projectile Shedder was destroying the Enemys if the path and waypoints collided with it. The simple solution was to set up a tag and check to make sure that it wasn’t an Enemy.

//using System.Collections;
//using System.Collections.Generic;
using UnityEngine;

public class Shredder : MonoBehaviour
{

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag != "Enemy")
        {
            GameObject.Destroy(collision.gameObject);
        }
    }
}

Hello Velcronator,
I had the same problem and couldn’t quite figure out what caused it.
Thanks to this tip it quickly became clear to me.

I do choose to tag my lasers and therefore only destroy objects with this tag.
afther all, the goal of the shredder is to remove just those lazers. :slight_smile:

So again, thank you very much for pointing me in the right direction

1 Like

Glad it was of use

Privacy & Terms