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);
}
}