using ActionGameFramework.Health;
using ActionGameFramework.Helpers;
using ActionGameFramework.Projectiles;
using UnityEngine;
namespace TowerDefense.Towers.TowerLaunchers
{
///
/// An implementation of ILauncher that firest homing missiles
///
public class HomingLauncher : Launcher
{
public ParticleSystem fireParticleSystem;
///
/// Launches homing missile at a target from a starting position
///
///
/// The enemy to attack
///
///
/// The projectile used to attack
///
///
/// The point the projectile is being fired from
///
public override void Launch(Targetable enemy, GameObject attack, Transform firingPoint,int idx = 0)
{
var homingMissile = attack.GetComponent();
if (homingMissile == null)
{
Debug.LogError("No HomingLinearProjectile attached to attack object");
return;
}
Vector3 startingPoint = firingPoint.position;
Vector3 targetPoint = Ballistics.CalculateLinearLeadingTargetPoint(
startingPoint, enemy.position,
enemy.velocity, homingMissile.startSpeed,
homingMissile.acceleration);
homingMissile.SetHomingTarget(enemy);
homingMissile.FireAtPoint(startingPoint, targetPoint);
PlayParticles(fireParticleSystem, startingPoint, targetPoint);
}
}
}