68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public class YoumuDeflect : Ability
|
|
{
|
|
private List<Projectile> projectilesInRange = new();
|
|
public float deflectionAngleMin = -48;
|
|
public float deflectionAngleMax = 90;
|
|
|
|
[Header("Effects")]
|
|
[SerializeField] private ParticleSystem deflectionParticles;
|
|
[SerializeField] private GameObject swordSweepEffect;
|
|
private float currentDissipationTime = 0f;
|
|
[SerializeField] private float dissipationTime;
|
|
|
|
protected override void AbilityEffects()
|
|
{
|
|
base.AbilityEffects();
|
|
swordSweepEffect.gameObject.SetActive(true);
|
|
currentDissipationTime = dissipationTime;
|
|
foreach (Projectile projectile in projectilesInRange.ToList())
|
|
{
|
|
if (!projectile)
|
|
{
|
|
projectilesInRange.Remove(projectile);
|
|
continue;
|
|
}
|
|
projectile.transform.eulerAngles = new Vector3(0, 0, Random.Range(deflectionAngleMin, deflectionAngleMax));
|
|
projectile.direction = projectile.transform.right;
|
|
projectile.tag = tag;
|
|
ParticleSystem newParticles = Instantiate(deflectionParticles, projectile.transform);
|
|
projectilesInRange.Remove(projectile);
|
|
}
|
|
}
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (!other.CompareTag(tag) && other.TryGetComponent(out Projectile isProjectile))
|
|
{
|
|
projectilesInRange.Add(isProjectile);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit2D(Collider2D other)
|
|
{
|
|
if (!other.CompareTag(tag) && other.TryGetComponent(out Projectile isProjectile) && projectilesInRange.Contains(isProjectile))
|
|
{
|
|
projectilesInRange.Add(isProjectile);
|
|
}
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
if (currentDissipationTime > 0)
|
|
{
|
|
currentDissipationTime -= Time.deltaTime;
|
|
if (currentDissipationTime <= 0)
|
|
{
|
|
swordSweepEffect.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|