82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using Core.Extensions;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public class EnemyBulletPattern : EnemyAbility
|
|
{
|
|
[Serializable]
|
|
public class ProjectileDirection
|
|
{
|
|
public Projectile projectile;
|
|
public Transform direction;
|
|
public float timing;
|
|
public int amount;
|
|
public float burstTiming;
|
|
public float projectileSpeed;
|
|
public bool aimedShot;
|
|
public Transform bulletParent = null;
|
|
}
|
|
|
|
[SerializeField] protected ProjectileDirection[] projectileDirections;
|
|
[SerializeField] private bool randomAim;
|
|
|
|
protected override void AbilityEffects()
|
|
{
|
|
base.AbilityEffects();
|
|
transform.Lookat2D(direction);
|
|
if (randomAim)
|
|
{
|
|
transform.eulerAngles = new Vector3(0, 0, Random.Range(0, 360f));
|
|
}
|
|
foreach (ProjectileDirection projectileDirection in projectileDirections)
|
|
{
|
|
if (projectileDirection.timing <= 0 && projectileDirection.amount <= 1)
|
|
{
|
|
ShootProjectile(projectileDirection.projectile, projectileDirection.direction.position, projectileDirection.projectileSpeed, projectileDirection.aimedShot, projectileDirection.bulletParent);
|
|
}
|
|
else if (projectileDirection.amount > 1)
|
|
{
|
|
StartCoroutine(BurstFire(projectileDirection, projectileDirection.amount,
|
|
projectileDirection.burstTiming));
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(DelayedShot(projectileDirection, projectileDirection.timing));
|
|
}
|
|
}
|
|
}
|
|
private IEnumerator BurstFire(ProjectileDirection projectile, int burstCount, float burstDelay)
|
|
{
|
|
int currentCount = 0;
|
|
while (currentCount < burstCount)
|
|
{
|
|
ShootProjectile(projectile.projectile, projectile.direction.position, projectile.projectileSpeed, projectile.aimedShot, projectile.bulletParent);
|
|
currentCount++;
|
|
yield return new WaitForSeconds(burstDelay);
|
|
}
|
|
yield break;
|
|
}
|
|
|
|
private IEnumerator DelayedShot(ProjectileDirection projectile, float delay)
|
|
{
|
|
float currentDelayTiming = 0f;
|
|
while (currentDelayTiming < delay)
|
|
{
|
|
currentDelayTiming += Time.deltaTime;
|
|
if (currentDelayTiming > delay)
|
|
{
|
|
if (projectile.amount > 1)
|
|
{
|
|
StartCoroutine(BurstFire(projectile, projectile.amount, projectile.burstTiming));
|
|
}
|
|
else
|
|
{
|
|
ShootProjectile(projectile.projectile, projectile.direction.position, projectile.projectileSpeed, projectile.aimedShot, projectile.bulletParent);
|
|
}
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|