using System; using UnityEngine; public class Projectile : MonoBehaviour { [Header("Base Stats")] public float lifetime; public float damage; [Header("Piercing")] public int pierceAmount; public int currentPierce; [Header("Movement")] [SerializeField] private Rigidbody2D rb; public float speed; private void Start() { Destroy(gameObject, lifetime); } private void FixedUpdate() { rb.linearVelocity = transform.right * speed; } protected void OnTriggerEnter2D(Collider2D other) { if (!other.CompareTag(tag) && other.TryGetComponent(out CombatEntity isEntity)) { currentPierce++; isEntity.TakeDamage(damage); if (currentPierce > pierceAmount) //if 0 then no one pierced. if 1 then can pierce 1 enemy and gets destroyed by second enemy, and so on... { Destroy(gameObject); } } } }