UnityGameProjectsCode / Rise2Point0Game / Tools / DestroyAfterTime.cs
DestroyAfterTime.cs
Raw
using UnityEngine;

public class DestroyAfterTime : MonoBehaviour
{
    //given a time, count in delta time until the time is reached. Once reached, destroy the attached object.
    public float waitTime;
    private float timeWaited;

    private void Update()
    {
        timeWaited += Time.deltaTime;

        if (timeWaited >= waitTime)
        {
            Destroy(this.gameObject);
        }
    }
}