How to Manage In-Game Time [Unity Tutorial]

  Рет қаралды 25,350

Comp-3 Interactive

Comp-3 Interactive

Күн бұрын

Пікірлер: 60
@mammels
@mammels Жыл бұрын
Hey thank you so much, I couldn't figure out how to make a if statement with strings but this video help me a huge ton and save me some much time. Thank you
@lukegamrivella2101
@lukegamrivella2101 4 ай бұрын
Thanks for the tutorial! Quick question, how will I keep record of my time across different scenes ? Won't the time reset to 00:00 when switching scenes ?
@simulation3120
@simulation3120 2 жыл бұрын
I wish I could have seen your inspector on TimeText, but overall much appreciated and helpful.
@xil2331
@xil2331 3 жыл бұрын
This is so cool and helpful! Loving this content!
@HannaOkonenko
@HannaOkonenko 9 ай бұрын
Thanks for your great job! tell me please what can be wrong if i see 11:60 not 11:00?
@damdakos
@damdakos 3 жыл бұрын
Great tutorial. I learned a lot. Thanks.
@neekitsart
@neekitsart 3 жыл бұрын
Thank you so much I've been struggling to find any useful tutorials about this
@danutorr
@danutorr Жыл бұрын
Fantastic vids, this and the previous one as well!
@boycececil3727
@boycececil3727 3 жыл бұрын
Great JOB!!! THX a lot, keep going !
@deepandrence4605
@deepandrence4605 3 жыл бұрын
Thanks a lot. You helped me a lot more than many videos and blogs. Thanks again.
@finalrenderanimationstudio
@finalrenderanimationstudio 3 жыл бұрын
Each time I think of systems not usually explored, shortly after I see you covering something Abt it, truly this was a great video,learnt alot too! Lol, got me thinking what's next? 😄
@ogulcanzorlu
@ogulcanzorlu 3 жыл бұрын
Great practical example on Actions.
@Kriskopower
@Kriskopower 2 жыл бұрын
Thanks. I do however have a problem. I tried to use this to implement day and night cycle in my project. Simply if the hour is 20 (20:00pm) i begin to decrease the RGB values of my SpriteRenderer image so it becomes darker. Then i check if the hour is 4 (04:00am) for example and i begin to slowly increase the same RGB values back to 255 to kinda simulate sunrise. It works fine and looks nice but after the first cycle it just doesnt happen anymore. Clock keep ticking like normal but my checks never get checked again and i dont know why :( I have added the same line as you added for the minute : "If the minute is >= 60 we reset it to 0 and we increment Hour by 1: hour++" but i added the same line for hour so if the hour >= 24 i say Hour = 0. So yeah the text clock appears to count normally but my checks only happens once for the first cycle and never again and i dont know why. Can you please help me with that ?!
@Wilhelm9218
@Wilhelm9218 2 жыл бұрын
Were you ever able to get it working? I’m having some difficulties as well. Are you calling your methods that decrease the values in an update function? My guess is that they are just being called once instead of in update where they would be checked every frame?
@archanachaurasia7811
@archanachaurasia7811 2 жыл бұрын
Sir can you make the day night cycle using this time manager. It would be a great help
@marto561
@marto561 5 ай бұрын
Just brilliant!
@bluebaldwin
@bluebaldwin 3 жыл бұрын
Really great tutorial and explanation! Keep it up pal 🤙 cheers
@pietro0games
@pietro0games 3 жыл бұрын
I thought about doing something like this, thanks for proving it
@Andrew-mg3ib
@Andrew-mg3ib 2 жыл бұрын
I think using DateTime and TimeSpan solves the redundancy of making your own time structures. And then you just change the update loop to add a minute every time an in-game minute passes. And then call a method that checks if hours, days, months, years have changed which fires events. If you wanted to handle days and months, you'd have to rewrite the complex code to do so, not to mention doing time calculations if you want to progress time.
@Kriskopower
@Kriskopower 2 жыл бұрын
Please can you help me with that...if you have the time to explain me the details in creating such a system of course. I would appreciate it very much.
@Andrew-mg3ib
@Andrew-mg3ib 2 жыл бұрын
​@@Kriskopower Google those c# structs. There's lots of documentation on them. Way more robust with lots of problems already solved. Was surprised he didnt just use them.
@Kriskopower
@Kriskopower 2 жыл бұрын
yup, yesterday i researched the DateTime built in struct and i made it work easily in my game. Just using the AddMinutes method and updating each frame accordingly.Also i really liked that the constructor is really rich, giving you the opportunity to define w/e time you need. Pretty neat :)
@ThePancakeJedi
@ThePancakeJedi 3 жыл бұрын
Wouldn't it kill performance by invoking an event every (half) second?
@christinaVennegerts
@christinaVennegerts 3 жыл бұрын
Amazing Tutorial, thank you very much!
@breecebossy8435
@breecebossy8435 Жыл бұрын
Thanks. I love the simplicity and versatility. I found that if I subscribe to hour and minute changed, then set something to happen at 6 && 0 (respectively), the method will execute on start, regardless of the hour condition not being met, as the 0 minute condition is instantly met. I fixed this by unsubscribing for minutes. Have I misused the system, or am i using it as it should be used?
@charg1nmalaz0r51
@charg1nmalaz0r51 Жыл бұрын
You were using it wrong. What is happening when the minute event riggers is anything subscibed to that minute event will run its function, same with the second event. If you hook up one function to two different events it will fire whenener those events fire. What you could do is sign it up to a timechanged event which passes the listener a struct that contains all the time information then you can check on your object when the time changes is the hour and minute 60 if so do this.
3 жыл бұрын
Impressive tutorial. Thank you for help.
@SkylorBeck
@SkylorBeck 3 жыл бұрын
Interesting way to do it. I personally prefer using an unsigned int or double, then increment it by one every fixed update. Then each fixed update just check to see if the current tick count is remainder 0 for your fixed update interval and increment another uint (or double) that represents seconds. Now you have a timer for ticks and a timer for seconds. You can remainder at different speeds to change your in game clock speed as well.
@KevsArtStuff
@KevsArtStuff 3 жыл бұрын
Awesome... need to get my head around Actions, but still, great video... thanks and subbed :)
@comp3interactive
@comp3interactive 3 жыл бұрын
I do actually have another video on my channel soully about Actions that you might find interesting!
@Vichroma
@Vichroma 2 жыл бұрын
question: i did the code but the update function literally does not work. i tried everything and it just doesn't run. the start function works just fine. any idea what could be causing this?
@lordlemonhead2732
@lordlemonhead2732 3 жыл бұрын
If I let my player walk into another scene, does the time continue where it left off or will it restart at its coded starting point?
@Definitely_a_Fox
@Definitely_a_Fox 2 жыл бұрын
A little late to the party but it would most likely restart. A simple way to make sure it continues is to make sure the object that keeps track of the time doesn't get deloaded when a new scene is loaded in. Simply add this line; DontDestroyOnLoad(this.gameObject); and it'll persist! I believe that the time will continue to tick on during loads, but I haven't tested it myself to make sure. Just make sure that you only ever have one of these time management objects in your scene at once, or it will cause some funky behaviour.
@elite_ramsay1667
@elite_ramsay1667 2 жыл бұрын
I was wondering how would i make it so on a button to pause the timer and one to resume the timer
@Wilhelm9218
@Wilhelm9218 2 жыл бұрын
I tried this and for some reason it the clock just keeps going up constantly per frame, regardless of what I set as the float (like in the example 0.5).
@astronuggie
@astronuggie 3 жыл бұрын
When I drag the TimeUI script to my clock object which is text, it says The script doesn't inherit a native class that can manage a script. I'm trying to only have in game time, not have it trigger actions yet. I can drag TimeManager but not UI
@mrmacka1456
@mrmacka1456 2 жыл бұрын
What object is the TimeBlock?
@abdou023
@abdou023 3 жыл бұрын
Is it okay to still subscribe and fire Actions if the script is on multiple GameObjects like an Enemy script would be on several enemies?
@jesseyules
@jesseyules 3 жыл бұрын
Q: What code would we need to trigger an animation using bool? (ie .SetBool("drive car", true);
@caracolina8785
@caracolina8785 3 жыл бұрын
Animator.SetBool("driving", true)
@mrmacka1456
@mrmacka1456 2 жыл бұрын
It says "Can't add script component 'TimeUI' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name can be found". Does anyone know how to fix this problem?
@do_it_like_rei
@do_it_like_rei 2 жыл бұрын
Same problem here with the time manager script
@do_it_like_rei
@do_it_like_rei 2 жыл бұрын
I FINALLY GOT IT WORKING FOR US! Okay so first make sure you have "using System;" in the assemblies at the top of the page, under using UnityEngine, etc. For the UI, make sure you also put "using TMPro;" up there or else you can't hook up the text to the script in your clock. Also in your public class make sure it's the name of your script. The time manager script wasn't working for me because for some reason it was set as New Behavior.
@ia2604
@ia2604 4 ай бұрын
@@do_it_like_rei I was just getting hung up on this when your comment set me free. Many thank yous!
@epiphanyatnight8732
@epiphanyatnight8732 3 жыл бұрын
Awesome tutorial! Would you recommend using UnityEvent instead of Actions? I usually consider UntiyEvents to be simpler but would love to know why you chose actions.
@comp3interactive
@comp3interactive 3 жыл бұрын
The benefits of using one over the other are mostly negligible, UnityEvents are slightly slower and come with more of an overhead, but they're visible in the inspector Personally I just use Actions coming from a non-gamedev C# background
@epiphanyatnight8732
@epiphanyatnight8732 3 жыл бұрын
@@comp3interactive Thanks for the reply, really helpful! Keep up the great work, I subbed!
@comp3interactive
@comp3interactive 3 жыл бұрын
Thanks man! Hopefully there'll be some more stuff on the channel you find useful too!
@F0r3v3rT0m0rr0w
@F0r3v3rT0m0rr0w 2 жыл бұрын
Quick question, the clock has a jittery effect, What would be the best approach to stopping that ?
@comp3interactive
@comp3interactive 2 жыл бұрын
You can use the tag to force monospace, that will stop the characters jumping around
@MrEastgalaxy
@MrEastgalaxy 2 жыл бұрын
damn some great tips.
@akaRDJC
@akaRDJC 3 жыл бұрын
idk if anyone can help me here but i wanna display am and pm strings that appear when the counter reaches 12 hours, am not looking for spoon fed answer as i wanna figure it out myself but if anyone has a hint in the direction id need to go to solve it that would be nice
@xkittencatx
@xkittencatx 3 жыл бұрын
Hi there! I only briefly glimpsed at the video, I'm in the process of rewatching it rn, but off the top of my head I would think that you'd make an if-else function checking if the hour counter is equal to 12 which would be P.M and then another function checking if the hour counter is equal to 24 A.M or vice versa. Basically, you'd be operating off of military time. But, I feel as if more people prefer the 12-Hour time set up we see on wall clocks and what not. In that case, I'd write some code that changes the 24 numerals back into the 12-Hour but changing the string to read P.M and A.M when necessary. I don't know if this helps or not but let me know!
@charg1nmalaz0r51
@charg1nmalaz0r51 Жыл бұрын
just do something like : string ampm = (if hours > 12
@random_precision_software
@random_precision_software 3 жыл бұрын
Can you tell me how much it cost for a sponsor please? Just asking for future reference for when I release my next game.
@comp3interactive
@comp3interactive 3 жыл бұрын
Hi man. Thanks for inquiring. Currently I can't accept new sponsors for my videos as I'm already sponsored by GigaTank3000 and don't really want to hammer ads and sponsors on the videos and turn people away, but the rates I charge are on my patreon, the sponsor tier is £50 for a months worth (4) videos
@random_precision_software
@random_precision_software 3 жыл бұрын
@@comp3interactive ok m8
@CHTOUROU_BECHIR
@CHTOUROU_BECHIR 3 жыл бұрын
Great
@domsim123
@domsim123 Жыл бұрын
Гарик Харламов?
How to Use Actions in Unity [Unity Tutorial]
14:49
Comp-3 Interactive
Рет қаралды 33 М.
How I learned Unity without following tutorials (Developing 1)
18:11
Game Maker's Toolkit
Рет қаралды 2,1 МЛН
Wall Rebound Challenge 🙈😱
00:34
Celine Dept
Рет қаралды 22 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
How to Add a Field of View for Your Enemies [Unity Tutorial]
23:45
Comp-3 Interactive
Рет қаралды 91 М.
The Unity Tutorial For Complete Beginners
46:39
Game Maker's Toolkit
Рет қаралды 4 МЛН
Can I Remake Super Mario World in Godot? (Part 1)
18:44
SCRIPTABLE OBJECTS in Unity
8:57
Brackeys
Рет қаралды 1 МЛН
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,3 МЛН
THIRD PERSON MOVEMENT in Unity
21:05
Brackeys
Рет қаралды 1,5 МЛН
What does a Game Engine actually do?
16:45
Ellie Rasmussen
Рет қаралды 172 М.
Making UI That Looks Good In Unity
18:06
Game Dev Guide
Рет қаралды 695 М.
I Wish I Had Known This Before I Started Unity Game Development...
11:11
Wall Rebound Challenge 🙈😱
00:34
Celine Dept
Рет қаралды 22 МЛН