Attackers dont take damage [fixed]


all worked fine untill i added the randum attackers spawned

fox.cs

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

public class Fox : MonoBehaviour
{
    private void OnTriggerEnter2D(Collider2D otherCollider)
    {
        GameObject otherObject = otherCollider.gameObject;

        if (otherObject.GetComponent<Gravestone>())
        {
            GetComponent<Animator>().SetTrigger("JumpTrigger");
        }



        if (!otherObject.GetComponent<Gravestone>())
        {
            if (otherObject.GetComponent<Defender>())
            {
                GetComponent<Atacker>().Attack(otherObject);
            }
        }
    }
}


health.cs

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

public class Health : MonoBehaviour
{
    [SerializeField] float health = 100f;
    [SerializeField] GameObject deathVFX;

    public void DealDamage(float damage)
    {
        health -= damage;
        if (health <= 0)
        {
            TriggerDeathVFX();
            Destroy(gameObject);
            
        }

       
    }
    private void TriggerDeathVFX()
    {
        if (!deathVFX) { return; }
        GameObject deathVFXObject = Instantiate(deathVFX, transform.position, transform.rotation);
        Destroy(deathVFXObject, 0.5f);
    }



}

private void OnTriggerEnter2Dfjf(Collider2D otherCollider)
    {
        var health = otherCollider.GetComponent<Health>();
        var attacker = otherCollider.GetComponent<Atacker>();

        if(attacker && health)
        {
            //reduce Damage
            health.DealDamage(damage);
            Destroy(gameObject);
        }
       
        {

        }
```maybe i spelled a litlle bit wrong

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms