chenxin
2020-10-27 43b531f76be6e12c775a1135f6895e8fdc389a59
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using ActionGameFramework.Health;
using ActionGameFramework.Helpers;
using ActionGameFramework.Projectiles;
using UnityEngine;
 
namespace TowerDefense.Towers.TowerLaunchers
{
    /// <summary>
    /// An implementation of ILauncher that firest homing missiles
    /// </summary>
    public class HomingLauncher : Launcher
    {
        public ParticleSystem fireParticleSystem;
 
        /// <summary>
        /// Launches homing missile at a target from a starting position
        /// </summary>
        /// <param name="enemy">
        /// The enemy to attack
        /// </param>
        /// <param name="attack">
        /// The projectile used to attack
        /// </param>
        /// <param name="firingPoint">
        /// The point the projectile is being fired from
        /// </param>
        public override void Launch(Targetable enemy, GameObject attack, Transform firingPoint,int idx = 0)
        {
            var homingMissile = attack.GetComponent<HomingLinearProjectile>();
            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);
        }
    }
}