Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Getting Object to Disappear After X amount of seconds

Discussion in 'Scripting' started by unity_46rq_Lp2-3Yrvg, Apr 15, 2018.

  1. unity_46rq_Lp2-3Yrvg

    unity_46rq_Lp2-3Yrvg

    Joined:
    Jan 28, 2018
    Posts:
    2
    How would I do this? I'm trying to get a door to disappear after 3 minutes, on a timer, and I'm unsure how to do this in C#! I know I should be making a true/false statement and if/then but I'm hesitant on its formulation. Thank you for all the help!
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Call Destroy(gameObject, 180) in the Start() of your door script.
     
  3. unity_46rq_Lp2-3Yrvg

    unity_46rq_Lp2-3Yrvg

    Joined:
    Jan 28, 2018
    Posts:
    2
    That was immensely helpful, @GroZZleR! I am wondering now if the procedure for enabling mesh renderer of an object would be similar? I'm working with this code and would like the collision to create or reveal a blockage behind the player (so that they cannot go back).

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class ChangeBox : MonoBehaviour {
    public Material Space_Nebula_DeepBlack;

    void OnTriggerEnter (Collider other) {
    if (other.gameObject.tag == "Player") {
    RenderSettings.skybox = Space_Nebula_DeepBlack;
    Destroy(this);
    }
    }