Basically I’m trying to make a an attack that appears a short distance in front of the player and destroys itself after x time (about 0.5 seconds) and inflicts each instance of damage 0.1 seconds apart for a max of 5 hits for each enemy, so if an enemy enters it late it will still take a few hits but the attack will end before they take their max of 5, but if you get 3 enemies in it for the entire duration they would each take 5 instances of damage 0.1 seconds apart. I’ve got most of it done but I’m struggling to figure out how to inflict the damage the way I’m trying to. I’ll put my code, its probably missing a bit cause I’m in-between ideas.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RapidAreaSlashHitScript : MonoBehaviour
{
public int CurrentDamage = 5;
public int HitAmount = 5;
public float Dur = .52f;
private bool HitReady = true;
private float KnockBack = 0;
private float MovementDelay = 0.3f;
// Start is called before the first frame update
void Start()
{
HitAmount = 5;
StartCoroutine(SelfDestruct());
}
private IEnumerator SelfDestruct()
{
yield return new WaitForSeconds(Dur);
Destroy(gameObject, 0f);
}
private void OnTriggerStay2D(Collider2D other)
{
if (other.CompareTag("Enemy") && HitReady == true)
{
HitReady = false;
StartCoroutine(Hit(other));
}
else if (HitAmount <= 0)
{
Debug.Log("Time to die!");
Destroy(gameObject, 0f);
}
}
private IEnumerator Hit(Collider2D enemy)
{
enemy.GetComponent<ClonableEnemyStats>().TakeDamage(CurrentDamage, KnockBack, MovementDelay);
yield return new WaitForSeconds(0.1f);
HitAmount--;
HitReady = true;
}
}