Answers for "unity add a delay in update function"

C
0

unity add a delay in update function

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

public class OverTime : MonoBehaviour
{
    private bool Timed;
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(CountDown(5));
    }

    // Update is called once per frame
    void Update()
    {
        if(!Timed)
        {
            StartCoroutine(CountDown(5));
        }
    }

    IEnumerator CountDown(float RestartAfter)
    {
        Timed = true;
        yield return new WaitForSeconds(RestartAfter);
        print(Time.time);
        Timed = false;
    }
}
Posted by: Guest on August-03-2021

Code answers related to "C"

Browse Popular Code Answers by Language