Working with Time in Unity

  Рет қаралды 114,456

Press Start

Press Start

Күн бұрын

Пікірлер: 103
@pressstart6864
@pressstart6864 6 жыл бұрын
Copy & Paste source code: pressstart.vip/tutorials/2018/07/20/45/building-a-timer.html
@NeedforSpeedMostWanted-yk4gz
@NeedforSpeedMostWanted-yk4gz 4 жыл бұрын
can we say timeStart = -Time.deltaTime; why cant this work ?
@Tomatexyz
@Tomatexyz 2 жыл бұрын
@@NeedforSpeedMostWanted-yk4gz -=
@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!)
@VisserStudio
@VisserStudio 5 жыл бұрын
Works like a charm. Out of all the tutorials I've watched this is the first one where I see the ? and : being used.
@encounter8
@encounter8 5 жыл бұрын
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!!
@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.
@gralegath
@gralegath 2 жыл бұрын
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.
@yahyashafqat7352
@yahyashafqat7352 4 жыл бұрын
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
@СтешаВласова-г5й
@СтешаВласова-г5й Жыл бұрын
I LOVE YOU BRO, YOU MADE MY DAY
@stavi975
@stavi975 3 жыл бұрын
good tutorial! Without you i couldn't figure out how to work with time, good explanation also!
@imvincible1391
@imvincible1391 4 жыл бұрын
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 4 жыл бұрын
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.
@troys1426
@troys1426 3 жыл бұрын
That was rly intuitive solution ngl
@miliuskairys6595
@miliuskairys6595 3 жыл бұрын
Thank you soo much. A very simple and effective tutorial
@IamHappyHi
@IamHappyHi 5 жыл бұрын
Exactly what I need! Great job! Thank you soooooooooooo much :)
@jort9546
@jort9546 4 жыл бұрын
Excellent video! You're great at explaining things.
@stickystick5569
@stickystick5569 4 жыл бұрын
Simple and Very informative. Thank you!
@PaperMickaelle
@PaperMickaelle 3 жыл бұрын
Thanks for the tutorial! Still a beginner and this helped me a lot. :-)
@borahaemypreciousbts7972
@borahaemypreciousbts7972 4 жыл бұрын
Thank you so much! Clear expanation! Great video!
@sheepFactory
@sheepFactory 3 жыл бұрын
Love you brother thank you so much for this.
@manuelfont4494
@manuelfont4494 5 жыл бұрын
Thank you very much for this tutorial
@justsomeclips_
@justsomeclips_ 3 жыл бұрын
hey man thank you! Got a really good tip from your video :)
@lavycube3521
@lavycube3521 4 жыл бұрын
Thank you for a great video, exactly what I was looking for👍
@Wendell-om3nq
@Wendell-om3nq 4 жыл бұрын
AMAZING, idn what is better the explanation or all the shortcut syntax code that I've just learned!
@tanasedaniel54
@tanasedaniel54 4 жыл бұрын
How can I change the format to minute?
@AbdulRahman-vt4bw
@AbdulRahman-vt4bw 4 жыл бұрын
Thanks a lot this tutorial is very helpful. :))
@razvand784
@razvand784 4 жыл бұрын
Thanks!You help me a lot!
@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!
@_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!
@NeuroDeveloper
@NeuroDeveloper 4 жыл бұрын
I really like how you speak.
@nibor9183
@nibor9183 4 жыл бұрын
Tnx dude, you helpt me a LOT
@CubeMasterLewis
@CubeMasterLewis 4 жыл бұрын
Very helpful. Thank you
@red_app1418
@red_app1418 4 жыл бұрын
great tutorial thank you!
@jennawrightson24
@jennawrightson24 4 жыл бұрын
thank you for the tutorial ..
@joelcollegework191
@joelcollegework191 4 жыл бұрын
Do you know how to make it so the timer does not reset upon changing a scene? Great tutorial!!
@domedin9894
@domedin9894 3 жыл бұрын
try storing the date in a variable
@CJRH1FILMS
@CJRH1FILMS 4 жыл бұрын
Excellent Tutorial. +1 Subscription
@drtrouser
@drtrouser 2 жыл бұрын
So good!!
@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?
@RTDTim
@RTDTim Жыл бұрын
THANK YOU GUY!
@PurpleLion1214
@PurpleLion1214 4 жыл бұрын
What code can i add if i want something to happen when the timer reaches 0?
@infernojoe
@infernojoe 4 жыл бұрын
if(timer
@Ryan22_7
@Ryan22_7 2 жыл бұрын
This is so simple. Why is every other tutorial so complex???
@upowlnight
@upowlnight 3 жыл бұрын
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
@jglasshalfpool4640
@jglasshalfpool4640 5 жыл бұрын
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 kzbin.info/www/bejne/n6nPepSDqs2emK8
@DashMatin
@DashMatin 5 жыл бұрын
YEAH MAKE ME SUFFER BY USING THE LIGHT MODE
@Fartmeister222
@Fartmeister222 3 жыл бұрын
Lul
@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.
@paulinox668
@paulinox668 2 жыл бұрын
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.
@dennisgonzales9521
@dennisgonzales9521 5 жыл бұрын
Can u make a tutorial about what and when to use Time.Deltatime and the Time.FixedDelta time? Thanks 😀😁
@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?
@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)
@neozoid7009
@neozoid7009 3 жыл бұрын
How to make it as hour system??
@realtalkwithharris6053
@realtalkwithharris6053 Жыл бұрын
what do you mean "option key"?
@tumpperi3891
@tumpperi3891 4 жыл бұрын
How did you get a dot instead of a comma?
@-Kadir_Demirci-
@-Kadir_Demirci- 3 жыл бұрын
The second start pause system doesn't work. I am sure ı did exactly everything like in video. But first worked.
@TDAdoesminecraft
@TDAdoesminecraft 4 жыл бұрын
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
@jeankasumi
@jeankasumi 4 жыл бұрын
How do I script a time stop when the game is over?
@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
@Stunt_sector
@Stunt_sector 2 жыл бұрын
Когда я на on click ставлю Main camera нету функции StopWatch
@princesszelda2072
@princesszelda2072 5 жыл бұрын
I need a countdown that works with minutes and seconds for a timed game mechanic
@emretasdemiir
@emretasdemiir 3 жыл бұрын
same here,anything?
@volokkolov9546
@volokkolov9546 3 жыл бұрын
thank you
@azyjmexcuseokstop924
@azyjmexcuseokstop924 3 жыл бұрын
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
@КонстантинЛактионов-щ1ю
@КонстантинЛактионов-щ1ю 3 жыл бұрын
very cool
@nickarry
@nickarry 5 жыл бұрын
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!
@karas9570
@karas9570 5 жыл бұрын
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.
@rainoffire919
@rainoffire919 4 жыл бұрын
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
@DonGT
@DonGT 5 жыл бұрын
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 }
@erenaydin
@erenaydin 2 жыл бұрын
thans a lot
@dawaysss7987
@dawaysss7987 2 жыл бұрын
Great tutorial but when it reaches 0 it keeps going to -1
@wellingtonhiciano2954
@wellingtonhiciano2954 2 жыл бұрын
you miss the part to reset the timer back to 0 when it reaches 60 seconds
@thebrownfrog
@thebrownfrog 3 жыл бұрын
thanks
@NeedforSpeedMostWanted-yk4gz
@NeedforSpeedMostWanted-yk4gz 4 жыл бұрын
can we say timeStart = -Time.deltaTime; why cant this work ?
@mahmoudtarek4506
@mahmoudtarek4506 4 жыл бұрын
Just cool
@jakeboi1449
@jakeboi1449 3 жыл бұрын
make a stop time tutorial
@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
@7even-h4n
@7even-h4n 4 жыл бұрын
55:50
@noniceq2096
@noniceq2096 3 жыл бұрын
still work :)
@issaelalexanderynumazenten552
@issaelalexanderynumazenten552 3 жыл бұрын
Time.deltaTime always give me the same value
@GemTappX
@GemTappX 2 жыл бұрын
A comment.
@gasliiuk4244
@gasliiuk4244 4 жыл бұрын
I was here when the like where at "609" XD
@hannorasmusholtiegel6044
@hannorasmusholtiegel6044 5 жыл бұрын
0 disliles ,nice
Unity - Creating a Level Select Screen in C#
16:23
Press Start
Рет қаралды 36 М.
Spawning Objects in Unity [Using Instantiate]
10:23
Press Start
Рет қаралды 241 М.
Air Sigma Girl #sigma
0:32
Jin and Hattie
Рет қаралды 45 МЛН
Unity Movement [RigidBody vs Translate]
9:00
Press Start
Рет қаралды 287 М.
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,3 МЛН
Switching Between Scenes in Unity 3D using UI Button
13:33
CG AURA
Рет қаралды 68 М.
Can You Beat Minecraft From One Grass Block?
35:27
Beppo
Рет қаралды 6 МЛН
How I learned Unity without following tutorials (Developing 1)
18:11
Game Maker's Toolkit
Рет қаралды 2,1 МЛН
5 ways to make your unity3d code faster
20:14
Jason Weimann (GameDev)
Рет қаралды 58 М.
Adding Graphics Options To Your Games - Complete Unity Menu System
19:08
Building a Localization Tool in Unity - Part 1
8:25
Game Dev Guide
Рет қаралды 64 М.
Level selection in your Unity game | Unity tutorial
11:08
Coco Code
Рет қаралды 67 М.