59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public abstract class Projectile : MonoBehaviour
|
|
{
|
|
[Header("Projectile")]
|
|
[SerializeField, Range(0, float.MaxValue)]
|
|
private float _speed = 5.0f;
|
|
[SerializeField]
|
|
private DirectionEnum _direction;
|
|
|
|
private int _damage;
|
|
private Entity _origin;
|
|
private Vector2 _startPos;
|
|
|
|
protected virtual void Start()
|
|
{
|
|
if (Direction == DirectionEnum.Left)
|
|
{
|
|
_speed = -_speed;
|
|
}
|
|
_startPos = new Vector2(_origin.transform.position.x, _origin.transform.position.y);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
ApplyMovement();
|
|
if (transform.position.x < -100.0f || transform.position.x > 100.0f)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
HandleCollision(other);
|
|
}
|
|
|
|
protected virtual void ApplyEffects(Entity target) { }
|
|
|
|
protected abstract void ApplyMovement();
|
|
|
|
protected abstract void HandleCollision(Collider2D other);
|
|
|
|
public float Speed { get => _speed; set => _speed = value; }
|
|
public int Damage { get => _damage; set => _damage = value; }
|
|
private DirectionEnum Direction { get => _direction; set => _direction = value; }
|
|
public Entity Origin { get => _origin; set => _origin = value; }
|
|
public Vector2 StartPos { get => _startPos; set => _startPos = value; }
|
|
|
|
protected enum DirectionEnum
|
|
{
|
|
Right,
|
|
Left
|
|
}
|
|
}
|