Unity チュートリアルのタワーディフェンステンプレートを触ってみる(20)

Unity チュートリアルのタワーディフェンステンプレートを触ってみる(19)では LaserTower_0 に追加した AttackAffector の解説を行った。今回は LaserTower_0 に追加した HitscanLauncher のインタフェースである ILauncher の解説を行っていく。

1.標的設定と砲撃編 – ILauncher.cs

ILauncher.cs について稚拙ながら解説

「ILauncher.cs」は「Assets/Scripts/TowerDefense/Towers/ILauncher.cs」の指しておりスクリプトについては以下の通り。内容としては砲撃処理の関数定を行っている。

[cce_csharp]using System.Collections.Generic;
using ActionGameFramework.Health;
using UnityEngine;

namespace TowerDefense.Towers
{
    /// <summary>
    /// A class that allows the TowerConfiguration to delegate
    /// different firing logic this component
    /// </summary>
    public interface ILauncher
    {
        /// <summary>
        /// The method for crafting the firing logic for the tower
        /// </summary>
        /// <param name="enemy">
        /// The enemy that the tower is targeting
        /// </param>
        /// <param name="attack">
        /// The projectile component used to attack the enemy
        /// </param>
        /// <param name="firingPoint"></param>
        void Launch(Targetable enemy, GameObject attack, Transform firingPoint);

        /// <summary>
        /// The method for crafting the firing logic for the tower
        /// </summary>
        /// <param name="enemy">
        /// The enemy that the tower is targeting
        /// </param>
        /// <param name="attack">
        /// The projectile component used to attack the enemy
        /// </param>
        /// <param name="firingPoints">
        /// A list of firing points to fire from
        /// </param>
        void Launch(Targetable enemy, GameObject attack, Transform[] firingPoints);

        /// <summary>
        /// The method for crafting firing logic at multiple enemies
        /// </summary>
        /// <param name="enemies">
        /// The collection of enemies to attack
        /// </param>
        /// <param name="attack">
        /// The projectile component used to attack the enemy
        /// </param>
        /// <param name="firingPoints"></param>
        void Launch(List<Targetable> enemies, GameObject attack, Transform[] firingPoints);
    }
}[/cce_csharp]

23行目 : 「void Launch(Targetable enemy, GameObject attack, Transform firingPoint);」は砲撃処理を作成する関数の定義を行っている。

37行目 : 「void Launch(Targetable enemy, GameObject attack, Transform[] firingPoints);」も23行目と同様に砲撃処理を作成する関数の定義を行っている。ここでは複数の発射地点を想定している

49行目 : 「void Launch(List<Targetable> enemies, GameObject attack, Transform[] firingPoints);」も23行目と同様に砲撃処理を作成する関数の定義を行っている。ここでは複数の発射地点かつ複数の的に砲撃することを想定している

%d人のブロガーが「いいね」をつけました。