Shoot-N-Slash/Assets/Scripts/Abilities/Parry.cs

46 lines
1.1 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Core.Extensions;
using UnityEngine;
public class Parry : Ability
{
public List<Projectile> projectilesInRange = new();
protected override void Update()
{
base.Update();
transform.Lookat2D(thisEntity.attackOriginPoint.position);
}
protected override void AbilityEffects()
{
base.AbilityEffects();
foreach (Projectile projectile in projectilesInRange.ToList())
{
if (!projectile)
{
projectilesInRange.Remove(projectile);
continue;
}
projectile.transform.eulerAngles = new Vector3(0, 0, 180);
projectile.direction = -projectile.transform.right * projectile.speed;
projectile.tag = thisEntity.tag;
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag(thisEntity.tag) && other.TryGetComponent(out Projectile isProjectile))
{
projectilesInRange.Add(isProjectile);
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (!other.CompareTag(thisEntity.tag) && other.TryGetComponent(out Projectile isProjectile) && projectilesInRange.Contains(isProjectile))
{
projectilesInRange.Remove(isProjectile);
}
}
}