44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class StraightProjectile : Projectile
|
|
{
|
|
[Header("Straight Projectile")]
|
|
[SerializeField]
|
|
private int _maxHitEntities = 1;
|
|
|
|
private List<Entity> _hitEntities = new List<Entity>();
|
|
|
|
protected override void ApplyMovement()
|
|
{
|
|
transform.position += new Vector3(Speed * Time.deltaTime, 0.0f, 0.0f);
|
|
}
|
|
|
|
protected override void HandleCollision(Collider2D other)
|
|
{
|
|
if (other.CompareTag(Origin.tag)) return;
|
|
|
|
if (other.TryGetComponent(out Entity target) &&
|
|
!HitEntities.Contains(target) &&
|
|
HitEntities.Count < MaxHitEntities)
|
|
{
|
|
ApplyEffects(target);
|
|
target.Hit(Damage);
|
|
HitEntities.Add(target);
|
|
if (target.Hp <= 0)
|
|
{
|
|
target.Death();
|
|
}
|
|
}
|
|
|
|
if (HitEntities.Count >= MaxHitEntities)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
public List<Entity> HitEntities { get => _hitEntities; set => _hitEntities = value; }
|
|
public int MaxHitEntities { get => _maxHitEntities; set => _maxHitEntities = value; }
|
|
}
|