Before seeing Rick’s solution, I created this self destruct script. I actually laughed when I saw how simple and more straight forward Rick’s solution was. Is my script too expensive since it relies on Update()?
Thanks!
using UnityEngine;
public class DestroyTimer : MonoBehaviour
{
[SerializeField] float timeUntilDestroyed = 2f;
float currentTime = 0f;
private void Update()
{
currentTime += Time.deltaTime;
if (timeUntilDestroyed <= currentTime)
{
Destroy(gameObject);
}
}
}