Advertisement
johnnygoodguy2000

DestroyObjectOverTime.cs

May 2nd, 2024 (edited)
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class DestroyObjectOverTime : MonoBehaviour
  6. {
  7. public float lifeTime; // How long the object should live
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11.  
  12. }
  13.  
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. lifeTime -= Time.deltaTime;// Subtract Time.deltaTime from lifeTime
  18.  
  19. if(lifeTime <= 0)// If lifeTime is less than or equal to 0
  20. {
  21. Destroy(gameObject);// Destroy the game object
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement