How to EASILY make a TIMER in Unity

  Рет қаралды 38,235

AIA

AIA

Күн бұрын

Timers are often used in video games to give players a sense of urgency or display the current time on a special ability. In this session, we'll walk through how you can create a timer in Unity with c# for your own game that has a single click option to count up or count down. We'll also add a flash effect to the timer to its display once its time is up.
► Socials
Twitter: / the_real_aia
Discord: / discord
My free web games: aiadev.fun/
► Get the script: unicornone.gumroad.com/l/time...
► Unity UI Tutorial: • Unity UI Tutorial | An...
► Microsoft doc on string.Format: docs.microsoft.com/en-us/dotn...
► Download Unity 3D: on.unity.com/3cbxhXY
For more educational content on video game development, unity tutorials, and c# programming don't forget to subscribe!
Chapters:
0:00 Introduction
0:30 Creating the unity timer script
1:07 Basic unity countdown functionality
8:45 Flashing the display once time has expired
10:53 Adding an editor checkbox to switch between unity count down and count up
12:31 Outro
········································­­·······································­·­····
****
Get a 90% discount on a .fun domain for one year on www.get.fun using the coupon “AIA”
****
♪ Raspberry Music - A Lofi
#unity3d #unitytutorial #gamedev

Пікірлер: 43
@AIAdev
@AIAdev 2 жыл бұрын
How are you using a timer in your games?
@ivansav9142
@ivansav9142 2 жыл бұрын
for the onset of sudden death, approximately as in Worms
@jaymadethat1362
@jaymadethat1362 9 ай бұрын
For a camera delay timer for main character.
@Likeableleaf
@Likeableleaf 2 ай бұрын
Amazing brother, you helped me while on stream! thank you so much for being so cool :)
@skullydev5710
@skullydev5710 Жыл бұрын
Thank you so much
@Juanzett
@Juanzett 2 жыл бұрын
thanks for the nice tutorial!!! Great job
@AIAdev
@AIAdev 2 жыл бұрын
Thanks! Glad it was helpful:)
@Serious_Im
@Serious_Im 2 жыл бұрын
Thanks!
@IDENTICYEA
@IDENTICYEA Жыл бұрын
hey man thanks
@tontonton5791
@tontonton5791 2 жыл бұрын
hello, may I ask for help? my seconds timer seems to be invisible. but it functions fine. the minutes and the tens of seconds can be seen. only the seconds can't be seen going down. Thank you
@_arcadian._
@_arcadian._ Жыл бұрын
Awesome tutorial, works great. One question thought : if we are working with a count up how do we make the current time of the timer customiseable? I want to use the timer as a clock, so i want my game to look like in the beginning its 06:00 and it ends at 12:00. Thanks in advance!
@_arcadian._
@_arcadian._ Жыл бұрын
I figured it out, here is the solution for people who also want to do this: 1. add a private float for the time you want the count up timer (stopwatch) to start. I called mine currentTime. 2. the time formula is the same as the timeDuration (nf * 60f). I set mine to 6f, so that the timer would start at 06:00. 3. In the ResetClock void, in the else statement, instead of making clock = 0, make it equal the float you added. In my case, clock = currentTime; Now, that should work by itself to make your stopwatch start a certain time, but if you want to make it stop at a certain time as well, here is how to do it: 1. add a public bool for a time limit, and a public float a time limit. mine looked like this: [Header("Limit Settings")] public bool hasLimit; public float timeLimit; 2. in void Update, add an additional if statement in the beginning. i renamed some of my variables because i am calling my script a clock, so instead of clock yours should say time/timer (however you have written it as) it is a bit complicated, so i will just paste it here: if (hasLimit && ((countDown && clock = timeLimit))) { clock = timeLimit; UpdateClockDisplay(clock); enabled = false; } 3. under it, reference the Update Display void, i remained mine to UpdateClockDisplay(clock); but if you are following the tutorial yours is probably called UpdateTimer/TimeDisplay(time/timer) (i forgot which one is used and am kinda too lazy to check) 4. in unity you should be able to set the time limit. in order for it to work in the current format, it should look something like this: 1200 that's it! i managed to figure it out because i watched another tutorial by BMo, here is the link: kzfaq.info/get/bejne/q8WeZrF2zpiWY3k.html
@kara_7z
@kara_7z 2 жыл бұрын
TNX BRO ❤
@AIAdev
@AIAdev 2 жыл бұрын
You're welcome!
@Manardo18
@Manardo18 2 ай бұрын
Been having a problem where, if countdown is enabled, that the time is never set and the timer constantly flashes when I start my game.
@yojan69
@yojan69 Жыл бұрын
tysmmm
@matthiuealmacen3815
@matthiuealmacen3815 2 жыл бұрын
Sir good am/pm, do you know how to make a pause for the countdown?
@Cactusking1
@Cactusking1 9 ай бұрын
Were can I get the same numbers as you have in the tutorial?
@ivansav9142
@ivansav9142 2 жыл бұрын
good shit. I just splurged on my first comment of all time on KZfaq thanks a lot for a cool explanation
@AIAdev
@AIAdev 2 жыл бұрын
😮 maybe the coolest comment I’ve ever received TBH. You’re destined for greatness.
@ivansav9142
@ivansav9142 2 жыл бұрын
@@AIAdev is it possible to withdraw the received timer readings?
@ivansav9142
@ivansav9142 2 жыл бұрын
ok I took it from here -> string currentTime = string.Format("{00:00}{1:00}", minutes, seconds);
@AIAdev
@AIAdev 2 жыл бұрын
@@ivansav9142 im not sure what you mean
@AIAdev
@AIAdev 2 жыл бұрын
@@ivansav9142 did this solve your above question?
@raydani8748
@raydani8748 Жыл бұрын
I didn't get any of the tabs come up when I dragged the script onto the canvas
@terrenceskill3231
@terrenceskill3231 2 жыл бұрын
I need the Countdown for Rewarded Ads that only could be used once per hour
@rushabhgohel5182
@rushabhgohel5182 Жыл бұрын
how can i display hours similer way you show minutes and seconds?
@Zap.zz.
@Zap.zz. 2 жыл бұрын
how do save your best Times pls Respond Someone using PlayerPrefs
@TheGameLecturer
@TheGameLecturer Жыл бұрын
I don't get it, mine flashes all the time.
@dkordy
@dkordy 2 жыл бұрын
can you please help,NO ONE on the whole you tube dont tell how to stop cont down or count up when you need? can you help please!!!
@AIAdev
@AIAdev 2 жыл бұрын
you could add a new boolean variable like isPaused. Then in the update function do a check on isPaused. If it is true, return the function early. Then you just need to set the isPaused by whatever means you want
@dkordy
@dkordy 2 жыл бұрын
@@AIAdev i dont understand but thanks for replay.
@dkordy
@dkordy 2 жыл бұрын
I figured it out, thanks a lot! You're the only one who answered me. Thank you very much.
@cheery-hex
@cheery-hex Жыл бұрын
Ikr right like what's the point of having a timer that won't stop when the level ends lmao
@Superspy1764
@Superspy1764 Жыл бұрын
for anyone looking for a answer still all you do is make a public bool called isPaused and then at the top of the update void say if(isPaused) { return; } also to make sure it doesnt start paused add isPaused = false in the start void. so it would be void Start() { resetTimer(); isPaused = false } then in void update { if(isPaused) { return; } if(countdown && timer > 0) { timer -= Time.deltaTime; updateTimerDisplay(timer); } else if(!countdown && timer < timerDuration) { timer += Time.deltaTime; updateTimerDisplay(timer); } else { flash(); } }
@vc.2023
@vc.2023 Жыл бұрын
How come you missed to mention digital font in your tutorial?
@AIAdev
@AIAdev Жыл бұрын
oh I didn't think it was important. It's from Dafont.com
@patrickFREE.
@patrickFREE. Ай бұрын
does someone has the same error: NullReferenceException: Object reference not set to an instance of an object PointsSystem.UpdateTimerDisplay (System.Single time) (at Assets/Scripts/GameField/PointsSystem.cs:74) PointsSystem.Update () (at Assets/Scripts/GameField/PointsSystem.cs:50)
@nearraindrop116
@nearraindrop116 10 ай бұрын
Can someone either leave the code in the comments or help me out? I'm using unity 2D URP 2021.3.24f1 and i keep getting these 3 errors. I'm new to unity so if someone can help me out I would appreciate it! ERRORS: Assets\Timer.cs(31,38): error CS1002: ; expected Assets\Timer.cs(46,52): error CS1002: ; expected Assets\Timer.cs(47,52): error CS1002: ; expected Thanks in advance for any help!
@AIAdev
@AIAdev 10 ай бұрын
looks like you're forgetting to end a statement, or multiple statements with semicolons. ;
@nearraindrop116
@nearraindrop116 10 ай бұрын
@@AIAdev Ah thanks!
@nearraindrop116
@nearraindrop116 10 ай бұрын
i forget to do that offten
Unity Drag and Drop Script | (Unity 3D tutorial)
12:40
Unity Tutorial : Creating a Timer using a slider
8:05
CatoDevs
Рет қаралды 19 М.
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 14 МЛН
WORLD'S SHORTEST WOMAN
00:58
Stokes Twins
Рет қаралды 112 МЛН
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,4 МЛН
I remade MARIO KART but with RAGDOLLS
10:02
AIA
Рет қаралды 575 М.
6 Devs COMPETE to make the BEST AI
16:02
AIA
Рет қаралды 316 М.
Configurable TIMER / STOPWATCH Unity Tutorial
11:08
BMo
Рет қаралды 34 М.
Coding Adventure: Portals
16:06
Sebastian Lague
Рет қаралды 1,3 МЛН
The biggest lie in video games
15:18
AIA
Рет қаралды 1,7 МЛН
I Made The World's Hardest Game
9:48
AIA
Рет қаралды 47 М.
How To Make a Countdown Timer in Unity
12:33
Turbo Makes Games
Рет қаралды 63 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 699 М.
Oh, wait, actually the best Wordle opener is not “crane”…
10:53
How I learned Unity without following tutorials (Developing 1)
18:11
Game Maker's Toolkit
Рет қаралды 2 МЛН
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 14 МЛН