- Home /
mid code timer?
can some one show me an example of a timer happening mid code so i can dellay things happen
Comment
Answer by RahulRaman · Feb 03, 2020 at 01:34 AM
If you just want to delay an action then you should use a coroutine in c# as the following code :-
using System;
using System.Collections;
using UnityEngine;
public class SomeClass : MonoBehaviour
{
public void funcA()
{
// This will cal funcB after 2 seconds
StartCoroutine(coroutineA(funcB, 2f));
// This will cal funcC with first arguement a blank string after 0.2 seconds
StartCoroutine(
coroutineA(
// Use of lambda to call funcC with blank string arguement
() => funcC("")
, 2f)
);
}
public void funcB()
{
// Example function
}
public void funcC(object arguement)
{
// Example function 2 with arguement
}
IEnumerator coroutineA(Action action, float delay)
{
yield return new WaitForSeconds(delay);
action();
}
}
Your answer
Follow this Question
Related Questions
Better way for a timer to load a level? 1 Answer
Random Delay time 2 Answers
How to add a delay to a bomb explostion 1 Answer
deactivate script for time period when script is used 0 Answers
cooldown timers 0 Answers