 Hello guys, Crypto grounds here. Welcome back to another unity C sharp idle game tour video. This is episode 40. Okay. So today we're going to be doing We're gonna be messing with our game speed. So what I plan on doing is having a current add system and Make it so that when we watch it add We can add like an hour of two times game speed or something like that, okay? And yeah, I think we're gonna do that and I think the only way we're gonna be able to test this in here is by Having a button That cause it automatically because there's I mean I can't watch ads here because I want to get to the building part later on Okay, so let's just start with our UI Also, if you enjoyed this video and you learned something make sure you smash the like button subscribe to my channel if you're new And turn on those notifications Check out my other videos in the right corner up there and comment your feedback and anything below Also, check out my patreon if you want to support me in the description below Remember we're two away from anti-matter anti-matter dimensions Okay, so I'm gonna be doing this in our main screen here I'm gonna Kind of adjust some things now again our UI is not very good in this game. I'm gonna be completely honest It's everywhere, but I'm just making things add on to each other because I think that's what's really important is Getting the core Or not the core, but like the stuff that we need done in there Okay, so here I'm gonna have a button Again, I could just add another button or a pop-up or something But I'm just gonna put it in my main screen and what we can do here is have one of those Watch add Okay, so I have my user interface. So I have my watch add button. I have my game speed timer And I have my progress bar for that Um, you know what we actually don't need this progress bar. I just realized that It can just be this and then that this will be our button, I guess Okay, we can make this smaller too let's see Sliced oh, we don't have it sliced Yeah, this is just gonna be my pause button. Okay So this is located in the main screen. You can put wherever you want You can manage it however however you want you can have it be a pop-up on the side a little widget or whatever you want So let's get to the coding. So I'm gonna do this in my mat or my ad manager. Sorry. I cannot talk. I'm really tired Um, oh, what's this reward pop-up What is this thing? What is this guy doing here? um Reward add is this it? Oh, yeah Okay So let's head to our ad manager And I see the reason why I don't get any errors because I turned off my ad manager. No wonder why Okay, we're in our ad manager right now and This button right here is going to be a another watch ad right except we're going to do Wow, this is so incredibly laggy Okay, we're going to create another watch ad You know what let's have an int id we want to determine which um, which ad we're watching, okay So we're gonna add a public int Called add a type Okay, and we want to set our ad type in here once it's loaded because we want to show the ad And then we're going to assign add type to this id here Okay, and this this reward pop-up here is going to be based on our ad type because we're going to have another one I believe Yeah, okay. I see here Um, okay, so let's have a switch statement here In case you want to add more and here will be switch ad type okay, so Basically the not like the 100 coins one that I the one that's in the top header is going to be zero Okay, so that's just going to show this normally And then we're going to break that and then our case zero or case one is going to be a Uh, it can show up something else, but it's going to give us our Uh, let's see. What can I do here handle user earned reward? Okay, we're going to do the pop-up stuff later Or actually yeah, we're going to do that later. We should be doing the reward stuff Okay, so now in our handle user earned reward. We're going to determine this world a reward Based on what our ad type is Okay And again, just like this uh switch case statement here Zero is going to be the coins one and one is going to be the Is going to be the game speed, okay, so we need a variable for this so we're going to go to our player data class or wherever you store your data okay, and I don't have a I don't have a region for this. I'm just going to create one. It's going to be like ad related or something like that Okay, and this is going to be a double Now I would use floats But there's I've been I don't know why but I've been having some random issue with my Timers for floats that are like past three days or something like that I mean, unrealistically, you probably won't get it that long But just to be safe. I would use a double because some reason floats don't work at some point um, but we're going to call this uh game speed timer Or yeah game speed two times timer Okay And in here in our public player data, we're going to add this at the very bottom except we're going to set Game speed two times timer equal to zero cool So now in our ad manager, we're going to set game dot data Dot game speed timer plus equals one hour, which is Uh, 3600 seconds. Okay. And also I'm going to create a data variable Uh, var data equals game dot data to get rid of this game dot Right here. Okay So now we will get our our our reward Okay, and uh, let's see. Where is this pop up here? I want to create another one We're going to call this reward game speed pop up Okay We're going to set it to false at the beginning And in our close app reward, we're going to set this to false as well Also, you see how we set this to true in here We need to do the same thing in here Okay So we set these to false I mean to true and then we set them in the false in the close method. Okay, so we have our reward done We need to actually get the the timer going Okay, so I'm just going to handle it in here because I think we have a user or an update. Yeah, we do So we're just going to handle it in here So basically if, uh I'm just going to create var data equals game.data Okay, so with data.gameSpeed time area is greater than zero We also need a pause state for this too So in our player data manager, we're going to add another bool called public um Game speed pa or active or something like that active and we're going to set this to true automatically Okay So if the timer is great and zero and our game speed active Is true Then we are going to Uh, so tracked data.gameSpeed two times timer by time.delta time Times one Or in parentheses one divided by time Dot time scale Now time scale is what we use to adjust the game speed, right? And the reason why we want to multiply this because if our game is going two by two times faster Then time.delta time is going to run two times faster as well So our timer is going to run or is going to burn down faster than it should so doing this for example Now let's say it's going one per second and we do one divided by game speed two So you see how it's half now, right? But this is technically two because the game speed is uh, two Right, so it's always going to be one no matter what so that's the nice thing about this right here Okay, and we also want to set this time scale It's two Okay, so now the game should be running two times faster Your coins per second will be well. Yeah, pretty much is two times per second or two times faster. Yeah, okay else Um Else time dot time scale is equal to one. I think that's it Okay, and now I'm going to add another method Toggle game speed Okay, so Again like in here Take this. Okay, so if the time we're only going to do this if the timer is Uh, greater than zero Okay, so if our data equals game data if data game speed two times timer is greater than zero Then we are going to set this pause or this active bull Equal to the opposite of its current state. Okay, so now just switch between And yeah, so the timer won't drain if this is false Cool, this should be good to go. We just need to get our user interface done So let's add a text public text game speed two times timer text Okay, and And let's just throw this in here I don't think we have navigation in here. No, so we can do add a nift statement called game dot um Oh, what's our group name? main menu group, okay So we're going to do game dot main menu group dot game object dot active self now. We only want this timer to keep Uh updating if we're on this page right now Okay, and this is going to be equal to dollar sign so we can put variables in here two times game speed And then a colon and then we're going to have our timer here, which we need to do that And now we calculate this timer and I'm going to calculate this inside the same method too because otherwise it's just pointless calculation Uh, we're going to call var game speed Timer Formatted Okay, and now this is going to equal time span Dot from seconds then here we're going to put our data dot game speed two times timer So now we convert this into a time span from seconds Okay, and then in here so basically we convert seconds into a A date or not a date time But like a time span so like we can see days minutes hours seconds within how many seconds It's kind of like a conversion. Okay, so then in here we Put throw it in here and we're going to format it as D for day Double slash double backslash colon hour hour or hh for hour double backslash colon minutes and seconds Okay, so now this should automatically Format it to zero zero zero zero colon zero zero Sorry too many zeros zero colon zero zero colon zero zero zero zero just like this no matter what, okay Cool. So now we have our user interface done Okay, I think that's all we need to do And our reward pop up we will create that too because I haven't made that yet Okay, so we're going to have to replace a few things here. So our reward had our reward add here our close button Um, oh, we don't need to do that Yeah, because we're it's based on our current add type Oh one thing before I forget we want to reset this add type back to zero After we're done watching this add Or after we close the add, okay, so we don't need to do it here But we need to do it in one. So we're going to reset this back to zero Okay, and close add reward method And then in here we need to We need to change our watch Um our watch add buttons. So that's this one right here and the one in the header. So that's these two right here Okay, so now this is going to say missing add manager dot watch add. So you just need to replace that watch watch add it Okay And this is going to be set to zero And the parameter for this one right here is going to be set to one Perfect And our pause button here. We need to add another button component And click the plus drag our add manager Go to add manager and I think this is just toggle game speed. Yeah Okay, so now we're going to go to our add manager and Drag in our new ui. Oh, you still have to create this reward add Or the game speed one Okay, so this is what it looks like here. It's pretty basic rewarded add game speed Okay, and all you need to do here since we're using the same close add reward text and honestly I could just Simplify this Okay, so let's simplify close add reward. All you need to do is this. Okay, we can just close both of them like Honestly, it's not going to make any cp performance. It's just going to make our code a little shorter Okay, so nothing huge here And it's going to say thanks for watching the ad you get plus one hour of two times game speed something like that Okay And we can turn that off Save it And now we can't really test it So I want to test the pause and I can just give myself some time So let's play it. Uh, no, we need to drag our stuff first. So our game speed pop up And our timer text which is right here Okay, now save it Press play Alrighty, so now it's set to zero. This is our default as I mentioned before just like we did here And if we click the watch add, uh, it's going to say no reference because um See rewarded ad has not been initialized because Uh Well, what am I what am I trying to say? It's because of this right here Now we can initialize a rewarded ad if it doesn't exist because of no, no right here See how we do mobile ads on initialize and then we also Yeah, that's what I'm talking about. Yeah Now we don't have a rewarded ad Okay, it doesn't exist And when we create and load rewarded ad we do that here Okay, let's see. Do we even load it an ad? No, we don't so what we're gonna do here We're gonna bring I think I forgot this no wonder why people were getting errors. Okay, so Copy and paste is create and load rewarded ad and Move it to here. Okay. Move it to the end of your start method Okay, I forgot because I'm stupid So now you shouldn't get that initialized error anymore, but it also doesn't matter because um We're not going to get any ads anyways. So yeah, this is how we initialize it right here Which I've talked about in the ad video itself Okay, so now let's actually let's actually test this because we don't need to worry about this And honestly what we can do here is that we hide this Watch ad button, right? Okay, so I'll I'll do the same thing for this whole interface here unless you have some other way Of hiding this otherwise. I'm just gonna hide all maybe this a button. I don't know. That's up to you Okay, or I might even not do I might Blah I'm probably not even gonna do anything with this anyways because that's totally up to you What you want to do with it? Okay, so let's see. Let's go to our I guess our game manager Yeah, and see we have our timer here. So let's just drag this See we're dragging the timer it works perfectly So right now there we go now it's running So the game should be running two times faster So let's set this so we should be getting six e4 per second Yeah It's kind of hard to tell at first But another good way to see Is this right here or by mode. Why is there by mode? There we go. It's to watch this progress bar See how it's like reacting much faster than it would here see it goes down quite fast Now let's set this to zero So there is no more See it's uh, it's kind of hard to see without having like an animation playing Uh, okay, so let's see watch this see how fast it fills up if I add a timer You see it's a little it's a little difference and again, it's two times faster It depends how you visually see it, but it's there. It's working so we can pause it by just clicking this button here And uh, when this is paused let's replace this text with something Okay, so let's Let's grab this right here This data dot game speed active And what we'll do inside this text we will set um If this is false question mark So if it's not active that we're gonna, uh, we're gonna put two times game speed Paused okay, something like that and then another colon and if it's Active then we're gonna display the time here. Okay So I'm going to show you real quick There we go. Let's just add this there we go paused Yeah, like that. See now The timer is it running because it's paused and we will have our normal game speed but once we unpause it There we go it speeds up Anyway, guys, if you enjoyed this video make sure you smash that like button subscribe to my channel If you're new and turn on those notifications so you get notified for every single video every single awesome video Comment your feedback bugs anything questions. All you got to spam the comments Uh, let's see. Do I have anything else to say? Oh, yeah patron. We are still two away. So that unfortunately I had one person um Unfollow and I got one more new person So I'd like to shout out a few people from my patreons I don't want to say their last names because I because they haven't like told me I can't do this So I'm just gonna say the first names but Andrew Nathan Cameron Those are my three patreons. If you're interested the link's in the description We are two away from getting the antimatter dimension series and I'm pretty hyped about that. So anyways, check that out Also, check out my other videos on the top right corner. Anyways, thank you guys for watching. See you later