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

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

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

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

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

[cce_csharp]using ActionGameFramework.Health;
using TowerDefense.Towers.Projectiles;
using UnityEngine;

namespace TowerDefense.Towers.TowerLaunchers
{
	/// <summary>
	/// An implementation of the tower launcher for hitscan attacks
	/// </summary>
	public class HitscanLauncher : Launcher
	{
		/// <summary>
		/// The particle system used for providing launch feedback
		/// </summary>
		public ParticleSystem fireParticleSystem;


		/// <summary>
		/// Assigns the correct damage to the hitscan object and
		/// attacks the enemy immediately.
		/// Early return if there is not HitscanAttack.cs attached to the attact object
		/// </summary>
		/// <param name="enemy">
		/// The enemy this tower is targeting
		/// </param>
		/// <param name="attack">
		/// The attacking component used to damage the enemy
		/// </param>
		/// <param name="firingPoint"></param>
		public override void Launch(Targetable enemy, GameObject attack, Transform firingPoint)
		{
			var hitscanAttack = attack.GetComponent<HitscanAttack>();
			if (hitscanAttack == null)
			{
				return;
			}
			hitscanAttack.transform.position = firingPoint.position;
			hitscanAttack.AttackEnemy(firingPoint.position, enemy);
			PlayParticles(fireParticleSystem, firingPoint.position, enemy.position);
		}
	}
}[/cce_csharp]

30行目 : 「public override void Launch(Targetable enemy, GameObject attack, Transform firingPoint)」は単体の敵に対して砲撃を行っている。内容としては単体へ砲撃を行った後 、ParticleSystem の実行を行っている。

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