using System; using UnityEngine; public class Projectile : MonoBehaviour { [Header("Flags")] public bool deflectable = true; [SerializeField] private bool isPiercing; public bool playerBullet; //bad code [Header("Stats")] [SerializeField] private int projectileHealth = 2; public int damage; public float speed; public float lifetime; [Header("CACHE")] public Vector2 direction; public AudioClip projectileShootSFX; public float volume; [SerializeField] private Rigidbody2D rb; public SpriteRenderer sprite; protected virtual void Start() { Destroy(gameObject, lifetime); direction = transform.right; } private void FixedUpdate() { rb.linearVelocity = direction * speed; } protected virtual void OnTriggerEnter2D(Collider2D other) { if (!other.CompareTag(tag) && other.TryGetComponent(out Entity isEntity)) { if (playerBullet) { GameManager.instance.projectilesHit++; //bad. very bad. but i don't care right now } isEntity.TakeDamage(damage); if (!isPiercing) { Destroy(gameObject); } } } public void Deflected() { projectileHealth--; if (projectileHealth <= 0) { Destroy(gameObject); } } }