using UnityEngine; public class AsteroidController : MonoBehaviour { public int damage; [SerializeField] private float damageCooldown = 0.5f; private float currentTime; private void Start() { GetComponent().AddForce(transform.forward * 100f); } private void OnBecameInvisible() => Destroy(gameObject); private void OnCollisionStay(Collision other) { if (!other.gameObject.CompareTag("Player")) return; if (currentTime <= 0f) { other.gameObject.GetComponent()?.DealDamage(damage); currentTime = damageCooldown; } else { currentTime -= Time.deltaTime; } } private void OnCollisionExit(Collision other) { if (!other.gameObject.CompareTag("Player")) return; currentTime = 0f; } }