47 lines
1 KiB
C#
47 lines
1 KiB
C#
using System;
|
|
using Core.Extensions;
|
|
using UnityEngine;
|
|
|
|
public class Projectile : MonoBehaviour
|
|
{
|
|
[SerializeField] private Rigidbody2D rb;
|
|
[Header("Stats")]
|
|
public float damage;
|
|
public float speed;
|
|
public int pierceAmount;
|
|
private int currentPierce;
|
|
public float destructionTime;
|
|
|
|
private void Start()
|
|
{
|
|
Destroy(gameObject, destructionTime);
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
rb.linearVelocity = transform.right * speed;
|
|
}
|
|
|
|
public void RotateToTarget(Vector3 target)
|
|
{
|
|
transform.Lookat2D(target);
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
{
|
|
if (!collision.CompareTag(tag) && collision.TryGetComponent(out Entity isEntity))
|
|
{
|
|
isEntity.TakeDamage(damage);
|
|
currentPierce++;
|
|
if (currentPierce > pierceAmount)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
TurnHandler.instance.UpdateTurns();
|
|
}
|
|
}
|