Тёмный

Working with Time in Unity 

Press Start
Подписаться 24 тыс.
Просмотров 113 тыс.
50% 1

In this tutorial I explain how time.deltaTime works and how we can use it to build a stopwatch and a countdown timer.
SUBSCRIBE: bit.ly/2Js78lE
============
+0:30 Creating a Text Field
+1:10 Adding a Custom Google Font
+1:40 Creating a Countdown Script
+2:45 Explaining time.deltaTime
+4:40 Creating a Stopwatch Script
+5:45 Using a UI button to start/stop timer
+7:05 Changing our buttons text on the fly
COPY & PASTE SOURCE CODE:
pressstart.vip/tutorials/2018...
MORE TUTORIALS:
pressstart.vip/unity-tutorials

Опубликовано:

 

9 авг 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 105   
@pressstart6864
@pressstart6864 5 лет назад
Copy & Paste source code: pressstart.vip/tutorials/2018/07/20/45/building-a-timer.html
@NeedforSpeedMostWanted-yk4gz
@NeedforSpeedMostWanted-yk4gz 3 года назад
can we say timeStart = -Time.deltaTime; why cant this work ?
@Tomatexyz
@Tomatexyz Год назад
@@NeedforSpeedMostWanted-yk4gz -=
@VisserStudio
@VisserStudio 4 года назад
Works like a charm. Out of all the tutorials I've watched this is the first one where I see the ? and : being used.
@turbodildo
@turbodildo 5 лет назад
Holy shit this is well made explained! Thank you!!!
@pressstart6864
@pressstart6864 5 лет назад
Thank you :)
@gralegath
@gralegath Год назад
Simple and to the point. Exactly what I needed to have my day night cycle script run automatically, granted I'll need to modify the code here a tiny bit, but that's easy. Thank you so much.
@miliuskairys6595
@miliuskairys6595 2 года назад
Thank you soo much. A very simple and effective tutorial
@user-qs3gr4xr1u
@user-qs3gr4xr1u Год назад
I LOVE YOU BRO, YOU MADE MY DAY
@encounter8
@encounter8 4 года назад
Wow...I think your Unity tutorial should be listed as a course on Unity Learn. Your videos are just way more easier to follow through and practical. Thanks a lot for AWESOME tutorials!!
@jort9546
@jort9546 3 года назад
Excellent video! You're great at explaining things.
@stickystick5569
@stickystick5569 3 года назад
Simple and Very informative. Thank you!
@vasilygurzhiy
@vasilygurzhiy 5 лет назад
best explanation, I've found on yt, thank you for the tut!)
@pressstart6864
@pressstart6864 5 лет назад
Thank you for your kind words :)
@vasilygurzhiy
@vasilygurzhiy 5 лет назад
@@pressstart6864 totaly worth the job you've done!)
@happyhi2309
@happyhi2309 4 года назад
Exactly what I need! Great job! Thank you soooooooooooo much :)
@Clavertus
@Clavertus 5 лет назад
What a great video, I don't understand why you don't have more views and likes :D Good job mate, simple and to the point
@pressstart6864
@pressstart6864 5 лет назад
Thank you! We're new but we're growing slowly.
@stavi975
@stavi975 2 года назад
good tutorial! Without you i couldn't figure out how to work with time, good explanation also!
@manuelfont4494
@manuelfont4494 4 года назад
Thank you very much for this tutorial
@borahaemypreciousbts7972
@borahaemypreciousbts7972 3 года назад
Thank you so much! Clear expanation! Great video!
@lavycube3521
@lavycube3521 4 года назад
Thank you for a great video, exactly what I was looking for👍
@troys1426
@troys1426 2 года назад
That was rly intuitive solution ngl
@nibor9183
@nibor9183 4 года назад
Tnx dude, you helpt me a LOT
@sheepFactory
@sheepFactory 3 года назад
Love you brother thank you so much for this.
@razvand784
@razvand784 4 года назад
Thanks!You help me a lot!
@PaperMickaelle
@PaperMickaelle 3 года назад
Thanks for the tutorial! Still a beginner and this helped me a lot. :-)
@red_app1418
@red_app1418 4 года назад
great tutorial thank you!
@jennawrightson24
@jennawrightson24 4 года назад
thank you for the tutorial ..
@AbdulRahman-vt4bw
@AbdulRahman-vt4bw 4 года назад
Thanks a lot this tutorial is very helpful. :))
@CubeMasterLewis
@CubeMasterLewis 4 года назад
Very helpful. Thank you
@RTDTim
@RTDTim Год назад
THANK YOU GUY!
@justsomeclips_
@justsomeclips_ 3 года назад
hey man thank you! Got a really good tip from your video :)
@yahyashafqat7352
@yahyashafqat7352 3 года назад
Man why haven't I posted in 10 months Your tutorials were ans are great and have helped me improve a lot so it will be helpful if u posted again
@CJRH1FILMS
@CJRH1FILMS 4 года назад
Excellent Tutorial. +1 Subscription
@drtrouser
@drtrouser 2 года назад
So good!!
@volokkolov9546
@volokkolov9546 2 года назад
thank you
@NeuroDeveloper
@NeuroDeveloper 4 года назад
I really like how you speak.
@Wendell-om3nq
@Wendell-om3nq 3 года назад
AMAZING, idn what is better the explanation or all the shortcut syntax code that I've just learned!
@user-ch7yu6ig5o
@user-ch7yu6ig5o 2 года назад
very cool
@imvincible1391
@imvincible1391 3 года назад
If you wan't to make the countdown timer go up just switch, (Great vid!) timeStart -= Time.deltaTime; to timeStart += Time.deltaTime;
@NeedforSpeedMostWanted-yk4gz
@NeedforSpeedMostWanted-yk4gz 3 года назад
can we say timeStart = -Time.deltaTime; why cant this work ?
@oddept
@oddept 2 года назад
@@NeedforSpeedMostWanted-yk4gz Hey a year late. "timeStart -= TIme.deltaTime;" actually says "timeStart = timeStart - Time.deltaTime;" So it's removing it from the variable. "timeStart = -Time.deltaTime" is setting it to deltaTime, so not removing it. Don't know if you still needed this but incase someone else strolls onto this video and wonders why.
@thebrownfrog
@thebrownfrog 2 года назад
thanks
@erenaydin
@erenaydin 2 года назад
thans a lot
@Ryan22_7
@Ryan22_7 Год назад
This is so simple. Why is every other tutorial so complex???
@DashMatin
@DashMatin 4 года назад
YEAH MAKE ME SUFFER BY USING THE LIGHT MODE
@Fartmeister222
@Fartmeister222 3 года назад
Lul
@mahmoudtarek4506
@mahmoudtarek4506 4 года назад
Just cool
@noniceq2096
@noniceq2096 2 года назад
still work :)
@dennisgonzales9521
@dennisgonzales9521 5 лет назад
Can u make a tutorial about what and when to use Time.Deltatime and the Time.FixedDelta time? Thanks 😀😁
@tanasedaniel54
@tanasedaniel54 4 года назад
How can I change the format to minute?
@paulinox668
@paulinox668 Год назад
Cuando se tenga un problema, busca tutoriales en ingles, son mas directos, intuitivos, y no te dicen "Esto es así, por que si" , si no que te explican la lógica que hay detrás esa a sido mi experiencia con todos los videos en ingles que eh visto.
@jglasshalfpool4640
@jglasshalfpool4640 4 года назад
Great tutorial. Thank you. I'm using this for a lap timer and am stuck trying to get minutes working. The timer just increments so 1 minute 22 seconds is shown as "82.00". Any pointers on converting this into a min:sec:millisec format?
@alecz1k
@alecz1k 2 года назад
pretty sure you solved this since your post 2 years ago but for anyone else, this tut helped me incrementing minutes:seconds ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ixlIaMuhkbM.html
@nickarry
@nickarry 4 года назад
Wow. Liked and Subbed! Question, how can i edit it so that the countdown timer only begins once 2 objects (which i've tagged in unity) collide? Thanks!
@TDAdoesminecraft
@TDAdoesminecraft 3 года назад
Hey cool vid but one question how do u make the stopwatch go so that it can go continue across scenes and not get destroyed
@_dowool_
@_dowool_ 4 года назад
is there a way to add Reset function to the code? I am very new to coding and am struggling.. Please help!
@rainoffire919
@rainoffire919 3 года назад
when you decreasing timer with delta time you don't wanna go below zero actually to be negative number.Copy this code and you done: using UnityEngine; using UnityEngine.UI; public class CountDown : MonoBehaviour { public float TimeStart = 60f; public Text TextBox; bool stopTime = true; //Start is called before the first frame update void Start() { TextBox.text = TimeStart.ToString(); } //Update is called once per frame void Update() { if (stopTime) { TimeStart -= Time.deltaTime; TextBox.text = Mathf.Round(TimeStart).ToString(); //TextBox.text = TimeStart.ToString(); } if (TimeStart
@joelcollegework191
@joelcollegework191 3 года назад
Do you know how to make it so the timer does not reset upon changing a scene? Great tutorial!!
@domedin9894
@domedin9894 2 года назад
try storing the date in a variable
@walney2008
@walney2008 5 лет назад
hello, how to do for the enemy to have an AI, where he passes by plane at the top and launches bomb, and this one goes towards the player that are towers? thank you
@alrexomandam1774
@alrexomandam1774 4 года назад
how do I make a gameobject appear after a certain time is passed? For example the StopWatch just reached 30s and then I want my boss to appear when that specific time is reached?
@tumpperi3891
@tumpperi3891 3 года назад
How did you get a dot instead of a comma?
@marnixvanleeuwen6533
@marnixvanleeuwen6533 4 года назад
What code can i add if i want something to happen when the timer reaches 0?
@infernojoe
@infernojoe 3 года назад
if(timer
@CentroDocumentalSM
@CentroDocumentalSM 4 года назад
This is really helpful. However, I haven't managed to stop the stopwatch once it reaches 0...:(....it goes on to -1, -2, -3....can anyone help me? I'm not a programmer, but I am trying to learn step by step.
@princesszelda2072
@princesszelda2072 4 года назад
I need a countdown that works with minutes and seconds for a timed game mechanic
@emretasdemiir
@emretasdemiir 2 года назад
same here,anything?
@neozoid7009
@neozoid7009 2 года назад
How to make it as hour system??
@dawaysss7987
@dawaysss7987 2 года назад
Great tutorial but when it reaches 0 it keeps going to -1
@azyjmexcuseokstop924
@azyjmexcuseokstop924 2 года назад
shoulda used a coroutine if you are only conting seconds : as is, your first countdown uses the update function every frame while it could just use a coroutine every second, dividing performance hit by 60
@ManiX207
@ManiX207 4 года назад
.. damn now how does one get this trnslated onto a Target game object.... (so if you hit hte target the timere starts, and if you defeated the target the timer stops)
@juanlanuza282
@juanlanuza282 4 года назад
how would i be able to add 1 second of time to my timer whenever the player collides and picks up a collectible?
@nickarry
@nickarry 4 года назад
OnTriggerTimer.2D
@jeankasumi
@jeankasumi 3 года назад
How do I script a time stop when the game is over?
@realtalkwithharris6053
@realtalkwithharris6053 Год назад
what do you mean "option key"?
@sdisag9889
@sdisag9889 5 лет назад
Is there a way to do the stopwatch in the format of 00:00 or 00.00? Keeping it as seconds and milliseconds?
@pressstart6864
@pressstart6864 5 лет назад
This might help: string minutes = Mathf.Floor(timeStart / 60).ToString("00"); string seconds = (timeStart % 60).ToString("00"); textBox.text = minutes + ":" + seconds;
@pressstart6864
@pressstart6864 5 лет назад
For milliseconds do: milliseconds = (int)(timeStart * 1000f) % 1000;
@sdisag9889
@sdisag9889 5 лет назад
@@pressstart6864 Figured it out. Thank you so much!!
@pressstart6864
@pressstart6864 5 лет назад
@@sdisag9889 Great!
@wellingtonhiciano2954
@wellingtonhiciano2954 Год назад
you miss the part to reset the timer back to 0 when it reaches 60 seconds
@jakeboi1449
@jakeboi1449 3 года назад
make a stop time tutorial
@-Kadir_Demirci-
@-Kadir_Demirci- 2 года назад
The second start pause system doesn't work. I am sure ı did exactly everything like in video. But first worked.
@Martin-hj4re
@Martin-hj4re 5 лет назад
how can I start a UI Timer with OnTriggerEnter? I've searched pretty much the whole internet
@pressstart6864
@pressstart6864 5 лет назад
Using the code from this video, just set timerActive = true in your onTriggerEnter function, like so: public class StopWatch : MonoBehaviour { public float timeStart; public Text textBox; public Text startBtnText; bool timerActive = false; // Use this for initialization void Start () { textBox.text = timeStart.ToString("F2"); } // Update is called once per frame void Update () { if(timerActive){ timeStart += Time.deltaTime; textBox.text = timeStart.ToString("F2"); } } private void OnTriggerEnter(Collider other){ timerActive = true; } }
@SmashBros4339
@SmashBros4339 3 года назад
@@pressstart6864 Is there also a way we can stop and get rid of the stopwatch when the gameover screen comes?
@upowlnight
@upowlnight 2 года назад
This tutorial is really helpful to me. I'm new to coding so at 6:14 I dont really understand why you would write public void first. I dont understand what that means when people write things like Public Void, Private Void, Void Start, Void Update. I just try to blindly accept it, but I feel like I should understand. Is there some good documentation for noobs somewhere?
@steegray4688
@steegray4688 2 года назад
hey man, I only just started too but in case you were still wondering, here is a really basic and by no means comprehensive round up of what I've learned about it so far: void means it doesn't return a value, where things like float, int, or bool do, and is basically used to DO things as opposed to generate values. Public and Private basically means if that part of the code is accessible to other parts of the game/code or not. So if another script can use part of this one or not depends if it is public. Can also mean it's accessible from the inspector. Does that make sense?
@upowlnight
@upowlnight 2 года назад
@@steegray4688 wow, I appreciate the response. That was really helpful. So private void I can name stuff however I wish, and not worry if I use that name again for another variable in another void somewhere else.
@steegray4688
@steegray4688 2 года назад
@@upowlnight I believe so. If it's private it means nothing outside that script and whatever object it's attached to can access, so you could call it whatever really. I'm still learning of course so if this turns out to be untrue I take no responsibility haha
@DonGT
@DonGT 4 года назад
Would this work (this is just a test not an actual script) Public bool time; Void update() { If time == true() { Then insert the stuff you did in update } If timestart = 0; { Time = false; } If time == false { Debug.Log("Timer is at 0") } This took long to write cuz I'm on mobile but just asking if this would work for somthing to happen when timer runs out }
@user-lv4de2ph9k
@user-lv4de2ph9k 3 года назад
55:50
@issaelalexanderynumazenten552
@issaelalexanderynumazenten552 2 года назад
Time.deltaTime always give me the same value
@karas9570
@karas9570 4 года назад
It's good but,It's notworking .if I create public void timeButton and use Onclick input Main camera when play mode time is stop in 0.00 and no can click nothing.
@Stunt_sector
@Stunt_sector 2 года назад
Когда я на on click ставлю Main camera нету функции StopWatch
@YashSingh-rc1oq
@YashSingh-rc1oq 5 лет назад
but how should we stop the time at zero coz its decreasing continously in negative
@pressstart6864
@pressstart6864 5 лет назад
Just wrap it in an IF statement like so: if(timeStart
@NeedforSpeedMostWanted-yk4gz
@NeedforSpeedMostWanted-yk4gz 3 года назад
can we say timeStart = -Time.deltaTime; why cant this work ?
@hannorasmusholtiegel6044
@hannorasmusholtiegel6044 4 года назад
0 disliles ,nice
@GemTappX
@GemTappX Год назад
A comment.
@gasliiuk4244
@gasliiuk4244 4 года назад
I was here when the like where at "609" XD
Далее
Unity - Creating a Level Select Screen in C#
16:23
Просмотров 36 тыс.
Dear Game Developers, Stop Messing This Up!
22:19
Просмотров 688 тыс.
It was like a real simulation👩🏻‍💻
00:15
Просмотров 1,8 млн
Unity Movement [RigidBody vs Translate]
9:00
Просмотров 282 тыс.
Spawning Objects in Unity [Using Instantiate]
10:23
Просмотров 239 тыс.
20 Advanced Coding Tips For Big Unity Projects
22:23
Просмотров 162 тыс.
A Perfect Jump in Unity - A Complete Guide
17:05
Просмотров 75 тыс.
Unity Tutorial : Creating a Timer using a slider
8:05
Understanding framerate independence and deltatime
29:22
Configurable TIMER / STOPWATCH Unity Tutorial
11:08
Просмотров 34 тыс.