41 lines
903 B
C#
41 lines
903 B
C#
using System;
|
|
using Core.Extensions;
|
|
using UnityEngine;
|
|
|
|
public class Projectile : MonoBehaviour
|
|
{
|
|
public float damage;
|
|
public float speed;
|
|
private int currentPierced;
|
|
public int pierceAmount;
|
|
public float lifetime;
|
|
[SerializeField] private Rigidbody2D rb;
|
|
|
|
public void RotateToTarget(Vector3 target)
|
|
{
|
|
transform.Lookat2D(target);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
Destroy(gameObject, lifetime);
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
rb.linearVelocity = transform.right * speed;
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (!other.CompareTag(tag) && other.TryGetComponent(out Entity isEntity))
|
|
{
|
|
isEntity.TakeDamage(damage);
|
|
currentPierced++;
|
|
if (currentPierced > pierceAmount)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|
|
}
|