Shoot-N-Slash/Assets/Scripts/Projectile.cs

40 lines
1,016 B
C#

using System;
using UnityEngine;
public class Projectile : MonoBehaviour
{
public Entity owner;
public float damage;
public float lifetime;
private int currentPierced;
public int pierceAmount;
public float speed;
[SerializeField] private Rigidbody2D rb;
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.stats.TakeDamage(damage);
currentPierced++;
if (currentPierced > pierceAmount)
{
Destroy(gameObject);
}
}
else if (other.gameObject.layer == 3) //hard coded layer but who tf cares i'm not inputting the variable every time i make a projectile lol
{
Destroy(gameObject);
}
}
}