autoDisableGameObj.cs 499 B

123456789101112131415161718192021
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class autoDisableGameObj : MonoBehaviour
  5. {
  6. public float disableTime = 5f;
  7. /// <summary>
  8. /// This function is called when the object becomes enabled and active.
  9. /// </summary>
  10. void OnEnable()
  11. {
  12. StartCoroutine(DisableIteself());
  13. }
  14. private IEnumerator DisableIteself()
  15. {
  16. yield return new WaitForSeconds(disableTime);
  17. gameObject.SetActive(false);
  18. }
  19. }