1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
using UnityEngine; public class DestroyAfter : MonoBehaviour { public float destroyAfter = 5f; private void Update() { destroyAfter -= Time.deltaTime; if (destroyAfter <= 0f) { Object.Destroy(base.gameObject); } } }