Assets/Scripts/DestroyAutomatically.cs (6 lines of code) (raw):

using UnityEngine; public class DestroyAutomatically : MonoBehaviour { [SerializeField] private float destroyAfter; private void Start() => Destroy(gameObject, destroyAfter); }