Using a simple coroutine timer to hide an object – C# Unity 3D

coroutinetimerhideunity3d

This script will hide a gameobject of your choice after waiting 4 seconds.


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

public class simpleTimer : MonoBehaviour
{

    public GameObject objectToHide;

    void Start ()
    {
        StartCoroutine(hideObject());
    }
	

    public IEnumerator hideObject()
    {
        yield return new WaitForSeconds(4f);

        objectToHide.gameObject.SetActive(false);
    }

}

Leave a comment