The trigger is not activating

My enemies are not losing health so my trigger is not working. On the laser game object I have trigger on and both enemies have circle collider 2d. here is the code

for enemy.cs

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

public class Enemy : MonoBehaviour
{
    // the health that the enemy starts with 
    [SerializeField] float health = 100;


    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnTiggerEnter2d(Collider2D other)
    {
        //storing gameobject
        DamageDealer damageDealer=other.gameObject.GetComponent<DamageDealer>();
        health -= damageDealer.GetDamage();

    }

}

for DamageDealer.cs

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

public class DamageDealer : MonoBehaviour
{
    //damage delt 
    [SerializeField] int damage = 100;

    public int GetDamage()
    {
        //return damage dealt
        return damage;

    }
    public void Hit()
    {
        //destroy player or enemy
        Destroy(gameObject);
    }
}

and here is an errors that popped up today

Solved it just had to remake the enemy gameObject and it works now.

Privacy & Terms