You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
2 months ago
|
using Cinemachine;
|
||
|
using D2D;
|
||
|
using UnityEngine;
|
||
|
|
||
|
using static D2D.Utilities.CommonGameplayFacade;
|
||
|
|
||
|
public class LaserMember : SquadMember
|
||
|
{
|
||
|
[SerializeField] private float projectileForce = 10f;
|
||
|
[SerializeField] private PoolType bulletPrefab;
|
||
|
|
||
|
public override void Shoot(Transform target)
|
||
|
{
|
||
|
if (reloadTime > Time.time)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var bullet = _poolHub.Spawn(bulletPrefab, shootPoint.transform.position);
|
||
|
bullet.transform.rotation = Quaternion.LookRotation(transform.forward);
|
||
|
|
||
|
var projectile = bullet.GetComponent<ProjectileComponent>();
|
||
|
|
||
|
projectile.rb.velocity = Vector3.zero;
|
||
|
|
||
|
_audioManager.PlayOneShot(_gameData.laserClip, .5f);
|
||
|
|
||
|
var direction = (currentTarget.transform.position - shootPoint.transform.position).normalized;
|
||
|
projectile.rb.AddForce(direction * projectileForce, ForceMode.VelocityChange);
|
||
|
|
||
|
projectile.enterComponent.OnEnter -= HitEnemy;
|
||
|
projectile.enterComponent.OnEnter += HitEnemy;
|
||
|
|
||
|
reloadTime = Time.time + memberClass.ReloadDuration;
|
||
|
}
|
||
|
|
||
|
private void HitEnemy(Transform other, Transform @object)
|
||
|
{
|
||
|
if (other.CompareTag(_gameData.hittableTag))
|
||
|
{
|
||
|
other.GetComponent<IHittable>().GetHit(memberClass.Damage);
|
||
|
|
||
|
var muzzle = _poolHub.Spawn(_gameData.laserMuzzleVFX, @object.position);
|
||
|
muzzle.transform.rotation = @object.rotation;
|
||
|
}
|
||
|
}
|
||
|
}
|