can't get my killer obstacle to disappear

So I am trying to make my obstacle/killer to disappear first before I attempt to actually make it kill and reset the game, but I am struggling with that still. This below is my code but my obstacle doesn’t seem to really disappear when my player collides with it. yes, I do have box collider 2D and I do have is trigger box checked. my player collides with other things but not this killer obstacle. No need to worry about the damage or health variable for now. Help me with my issue please :)) Thank you

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

public class Killerboi : MonoBehaviour
{
    public int damage = 3;
    void OnTriggerEnter2D(Collider2D other)
    {
        if(other.CompareTag("Player"))
        {
            //death
            other.GetComponent<PlayerMovement>().health -= damage;
            Destroy(gameObject);
        }
    }
}

Assuming it is actually getting to the destroy (which I can’t tell from this), I suspect you’re just destroying the script, not the attached gameobject. Scripts are themselves gameobjects, so if you want to destroy the actual gameobject in the world you have to destroy transform.gameobject.

1 Like