ReisenYoumuOuting/Assets/Scripts/Abilities/EnemyAbility.cs
2026-07-13 17:46:02 -07:00

44 lines
No EOL
1.2 KiB
C#

using Core.Extensions;
using UnityEngine;
public class EnemyAbility : Ability
{
[SerializeField] private float cooldownDelta;
[SerializeField] private bool willLookAtPlayer;
protected virtual void Start()
{
cooldown += Random.Range(-cooldownDelta, cooldownDelta);
currentCooldown = Random.Range(0, cooldown);
}
public override bool TryAbility()
{
WaveManager.instance.audioSource.PlayOneShot(abilitySound, volume);
if (willLookAtPlayer)
{
direction = WaveManager.instance.GetRandomPlayerPoint();
transform.Lookat2D(direction);
}
return base.TryAbility();
}
public void ShootProjectile(Projectile projectile, Vector3 location, float speed, bool aimed, Transform bulletParent = null)
{
Projectile newProjectile = Instantiate(projectile, origin.position, Quaternion.identity);
if (bulletParent)
{
newProjectile.transform.SetParent(bulletParent);
}
Vector3 projectileDirection = location;
if (aimed)
{
projectileDirection = WaveManager.instance.GetRandomPlayerPoint();
}
newProjectile.transform.Lookat2D(projectileDirection);
newProjectile.damage = power;
newProjectile.tag = tag;
if (speed > 0f)
{
newProjectile.speed = speed;
}
}
}