Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Wait (seconds) unity c#

A topic by Oronopt created May 01, 2020 Views: 1,193 Replies: 12
Viewing posts 1 to 5
(1 edit)

Im wondering how to create a countdown timer that waits for like a minute. But you cannot see the time left.

Create a courotine

Which type of courotine? I googled courotine but only found multiple types of  courotines. Hope you can reply. Sincerely Oronopt

try something like: 


private IEnumerator wait(float time){

     yield return new WaitForSeconds(time);

}

Submitted (1 edit) (+1)

Assuming you're working with C# in Unity, check out Time.timeSinceLevelLoad. It's a read-only float that equals the time in seconds since the scene loaded.

Unity docs: https://docs.unity3d.com/ScriptReference/Time-timeSinceLevelLoad.html

Sorry but that is not quite what I’m looking for, but I appreciate your effort. Sincerely Oronopt.

You could use invoke.

Submitted

A co-routine with a "Yield WaitforSeconds" is probably what some people are referring to

You can find a sample here https://docs.unity3d.com/ScriptReference/WaitForSeconds.html

Co-routines are pretty awesome for handling something when you need a specific period of time to lapse before doing the next thing :)

You can also use the update method and Time.deltaTime to check if a certain amount of time has passed https://docs.unity3d.com/ScriptReference/Time-deltaTime.html.

Both methods should do what you are looking for :)

Looks like it could work, I’ll try it and then I’ll come back(: 

Thank you! It worked! Im new so I started screaming when it worked!

Submitted

Haha, glad to hear it worked and also the reaction it caused! :)  The first one is my method of choice for timed events most of the time :)

Haha Yes I did not bother trying the second one because time.deltaTime does not work on my computer/:

First one worked!