Hey guys, i cant seem to find a solution to make delay on my OnTriggerEnter, have tried yield return WaitForSecends(2) but yield return does not seem to work with OnTriggerEnter, any one who can help me?
My code look like this right now:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
I get the feeling there is some method-based way to do that in Unity that would be more optimal than using a timer, but you can always use timers. Here are a couple:
Then you can have another function do something. Of course you have to determine when and where to reset your timer.
Here’s another:
while (timer < 10)
{
timer += Time.deltaTime;
}
return;
You could also use a for-loop.
for(i = 0, i < 10, i += Time.deltaTime)
{
doSomething();
}
If you don’t know why Time.deltaTime results in “1 second” - spend today wrapping your brain around that; it’s a simple but important concept you need to know to program most anything in unity. Imagine arbitrarily long frames-
Time.deltaTime is the amount of time it took to complete the last frame. If each frame is a half-second long - it will take two frames to reach 1 - in one second. This logic continues no matter how short the frames are.
I’m not sure if that solves his problem because wouldn’t the first iteration of the coroutine still happen instantly? I have only been using coroutines for a day - I have written a total of two ever.
Thanks alot BoredMormon! it helped! and thanks clearoutlines for learning me what Time.deltaTime was Habby programming guys, and have a great next week