 Hey guys Crypto grounds here welcome back to another idle game tutorial video this is episode 18 And today we're going to be doing daily events. So now just a heads up. This is a single player only I don't want to get to the multiplayer side stuff because setting up the server Getting the leaderboard stuff is quite a hassle and I have not perfected it myself Now as a tradition now, I'm going to show my face just to prove I'm not an Indian and I am not scamming people on you to me All right. Anyways, so daily events we're gonna have seven different events But I'm only gonna code to just to show an example because I don't have time to come up with seven different events and Honestly, I want these events to be something that you make yourself because they're gonna be pretty basic They're just make click this button That's it. All right, so it'll be pretty basic buttons So I'm gonna have them reward a special currency. Sorry. All right. Sorry about that So I'm gonna have my events be like have a reward a special currency that are gonna It's gonna boost your production basically So I can add this on the header or you could put that wherever you want Wherever you like incur that to the top I'm gonna put a text here now I had some suggest you to put it somewhere where it won't be Interruptive, I guess or just wherever it seems necessary To be honest So I'm gonna do tokens as our event currency or we can just do event tokens I'm gonna do zero and then that will be a zero or one a one times a boost Make sure best fit is on you can make this bigger Change the color of this if you want to I can make them like blue or something make something pretty Blue maybe aqua. I like aqua All right, so you have our event tokens right there, so we're gonna make a fourth button Now this user interface is getting contrast I this is I'm we're at the point where we should have a header or a footer right here to manage our navigation Because stuff on the top is definitely not the way to go Especially if this is a mobile game I don't think people are gonna want to reach all the way to the top of the screen in order to get somewhere So yeah, for now, let's just have an events button right here We need to move stuff around first Main screen Yeah, we can just really have this in the right here if I want to in the center sure Okay, and then I remember name this to tokenist text This is our event tokens text right there And then our achievements button we're gonna name this events button Okay, this will be labeled as events or we can put daily events So you can do this in several ways you can do you can put new to the you can do events every one every 24 hours Or you can do it once every like new event So what I'm gonna do or you can do it like every hour is the same event But then you have a new one the next day that's how I do it for crypto clickers So it's an hourly event But every day there's a new one for an entire week and then it repeats So I'm going to do cool down base So you have you can do like six hours six hours You can do this event again, or you can wait till the next one if you really wanted to So we'll do that and I'll include that in our do we have offline progress? No, we don't okay I really I mean I have an offline progress video, which is the idle the clicker heroes tutorial video So you can implement that and if you guys really want me to do a new like separate offline video I will do that. I'll do offline progress and I'll show you how you can do all that kind of cool stuff Anyways, let's get on with events. So I'm just gonna copy and paste this Achievement screen to save our lives Rename it as events screen I'm gonna turn it on get rid of all of our achievement stuff And I want to turn off main screen Okay, so this will be our Events so we're gonna have two game objects. I'm gonna do a Monday and a Tuesday one Monday And a Tuesday event All right Make there make sure these are ankle stretch and you can set the left to zero zero zero So it's stretch to the entire canvas of the event screen Also, make sure these are a zeros to just to get rid of random numbers Zero zero Perfect, okay We're gonna control our events below the navigation so anywhere in here and I'm gonna actually Make this stretch. Let's see if this work. Yeah, that works perfectly. Okay Now you can do however you you can do the UI however you want to And we're just gonna come up with two super quick events So what does our event? Generally need so we need a text. We need a label. Let's give it some text a light 30 and I'm gonna do Event tokens plus zero. This will be our reward on completion I'm also gonna show you guys how to like end the event early to like if users like tired of playing it I can just leave it early. I'm gonna make this best fit Cool. We have our event tokens reward right there. We're gonna rename this reward text or just reward Okay, so our currency really can be anything How I do I have TRX which is a crypto and that's our that's my event currency that translates to your reward Which is the event tokens, so I'm gonna make this currency. Let's do This could be any currency you want let's make this What should this be I Don't know what this should be Maybe crypto grounds. We are creating crypto grounds That's our currency for the game. I guess we can say And actually I'd rather do plus zero event tokens And I want to make this the same color as our text up here I'm gonna make this bold Put an outline on it. I'd suggest you not to use outlines since it causes lag But for the sake of this I'm gonna do it anyways Come on text be big be big Be big My gosh, I am failing miserably Zero crypto grounds and then we get Zero event tokens cool awesome. Okay, and Now I don't want to get too advanced here. So actually we're just gonna copy a button here that I already did and then We can call this click create plus one create one crypto grounds This is so much fun. Am I right and then we're gonna have an upgrade here click upgrade improve creation improve creation plus one and then our cost will be 10 CG or crypto crypto grounds. I don't want to really write that all out So this is our event. That's literally it Actually, we have a few things we need to do We need to have a Game object create empty. We're gonna call this Unlocked this is for when the event is unlocked already. We want to stretch to the entire Monday game object And we'll just put everything in here and this will be a canvas group Actually now we can make this just an empty game object here and then we're gonna have a locked That says when to start stop. So we're gonna create button here or we can literally just copy and paste these Now you could do whatever you want with this button, but this will be my start and exit button And this will also have our cool-down timer too. So let's make this 50. I want this to be extremely bold All right, that's our event Pretty lame, but that's for you to be creative not just to do exactly what I do Because if this is your event, I'm sorry, but nobody's gonna really participate Except they're gonna participate just for the boost They're not gonna enjoy it. So make sure you make fun events if you're doing this Okay, and for Tuesday, let's create Tuesday real quick so we can turn off Monday Let's create Tuesday and actually let's let's give them names too. Let's say this is the Monday event Click this is completely about click now be more again work be more creative than me And actually make something unique Cool. We have our Monday events, which is click and obviously for Tuesday. It's going to be about Production so this will be the same button here But we are also going to create a production upgrade production upgrade gain plus one CG per second Cost 10 CG All right, that's it Pretty simple. Let's see And we can also have our same currency here You can also do a new currency if you really wanted to but I'm gonna use the same currency because that's my name And this will be Tuesday event And this will be production is again be creative All right We can get coding now So in order to successfully do this we need to be able to identify what day it is Okay, so let's jump straight to our code, which we are going to do it and Now honestly in my opinion, I would create a new script at this point So let's do that. We're gonna create a new script We're gonna call it event manager now Make sure it's not manager. Make sure it's manager Or whatever you want to name it But honestly during this entire time for each like game of like upgrades achievements They should honestly each be on its own script and events too. That's why I'm doing that right now. Oh We do have achievement. Oh, yeah, never mind, but yeah, make sure you actually, oh This is not the right event system Where's our game object? Okay, we need to create that create empty. Oh, why did I give that? Okay, event manager. We need to get rid of it from here See I make sure you have a new game object for that event game manager I'm gonna move these scripts to the side out of the canvas Okay Perfecto, let's hop right in All right, we are in our script. So we are going to start this with two things Let's get our layout done. So we have a canvas, which is our events and honestly We can we don't really have to manage anything here. Oh Okay, you do your thing So let's add let's go back to the main script unless you're doing this on one script and you just need to do what I do We are going to add a canvas called Public my goodness public Canvas events group Okay, we have our events group and we are going to add to our changed haves So case events We're gonna make game object set active true So also what I'm gonna do here I'm gonna add up a void here We're gonna do disable all right here. So this is not repetitive. We are going to disable all of these at once So make sure this is false false And then what we can do here is every time we change tabs We will call it disable all and we will only enable the one that we want to see There we go that kind of just shorts and shortens it especially for the The future when you have tons of these All right Now our navigation is done. We're going to add our UI So we're gonna have a public text Event tokens text all right Plain and simple first we got to import the unity or unity engine that UI namespace Okay, and I'm gonna start using arrays because honestly, it's a lot organized It's a lot more organized But I also want to show you something that you will need to learn in the future is Like how to actually properly declare the arrays So we have several of the same things we have two game objects So we are going to add public game object array Events and now what we can do is New game object array and then put two because we only have two but the problem is if we change just the three We can't do that. It's because it's already defined as two. We would have to create a separate events and Then we can change that to three So if we changed it so if we saved it go back to unity change this to three won't work If we come back if we rename it to like events D then we can change the number so then it redefines it This is where This is the solution for this you go to public void start and You set events equal to new game object to Okay That should work If not, hopefully it won't okay. I see this actually won't work But this is how you would actually change that right now what we could do is grab all of our Game objects automatically, but I really don't want to do that So knowing I'm only gonna have two events or actually there's gonna be a maximum of seven events. I would recommend you do New game objects seven, okay? Just so you have seven events all right And if you want to add more then you're just gonna have to rename this and change this to whatever number you want So that's kind of the problem with declaring Arrays like this on the outside Okay All right, so now we have our events we have two event objects for sure now we have a Few things we have a text array We will do reward text We will have a currency text currency text And now we have so it's this honestly really depends on how much stuff you have So if Monday is completely different than Tuesday then array is not gonna really work for this But since we know we have a cost only one cost text Sorry one cost text for each event we can easily just make an array here cost text Yeah, we'll just Cost text so remember that only works for that situation. Otherwise, I would recommend you just having certain text for that For each event if that makes sense So if I had two upgrades in Tuesday with two costs then in that situation I would do something like public text Monday or whatever the events is Monday cost Text one and let's say Tuesday is the one that has two we'll have Tuesday We can do Tuesday cost text one Tuesday cost text two or You can just do Tuesday cost text Equals new text and however many texts you know, you're gonna have maximum Otherwise again, you're gonna have to change this to if you want to change this after you important to unity So that case that would be to just like that, but in our situation. We don't need to do that So hopefully that makes sense if you guys have any questions below make sure you just Have any questions make sure you leave them down below okay, I Think we're good with our UI. Oh, right. We actually have to have our public text start text goes new text Seven now again, I'm only 10 two events. So I'm only gonna use two of these texts Okay, we don't need initial right now. We don't need to initialize anything here. All right We're gonna add some stuff Public we're gonna add a big double Actually, really this can be a float it depends on how big your events are gonna be but I'm gonna do big double So make sure you're aware of that. I've talked about this in the previous episode if you guys watched that A new big double right this will be our currencies. No, this will actually be our reward Now the problem is that we can't just like do the arrow thing and have an equation right here We have to actually do that in the update method Public void updates Okay, so we can do reward Zero is equal to for example Big double Dot pow no, we're gonna do log 10 And that will be our currency which we will add Eventually, so we'll just keep that there I guess Um, let's have our saved variables in our data class Okay, so I'm gonna put events here and now I'm gonna do public big double array So since I'm gonna say we are gonna have seven events we're gonna do Currencies actually we don't need to save currencies because if you go offline and come back your events gonna end That really doesn't make any sense. So what we can save here is Our event tokens public big double Event tokens, okay, and here what else do we need to save we need to save our timer So this will be a float actually so public float Event cool down equals new float and that will be a size of seven Now we are going to define them down here So this is a little different because we're using an array here But event tokens will simply be zero and event cool down We are going to use For int I equals zero I Is greater is less than event cool down dot count our dot length I plus plus and this will also be minus one because of index zero and Event cool down at index I will equal zero So when we do a full reset it will make sure to set all the cool downs back to zero Okay, even if only using two in our situation Now we can go back to our ward and that will be based on actually We need to make a big double Currencies here. This is where we put it now. So we're gonna create that new array with size seven And now reward zero is going to equal to Currency zero plus one now. This is important because if we do log zero, we're gonna get an NAN All right, and that that becomes a big problem Okay If you know what log is log is basically we will draw this out I Don't want to go all the way to Desmos. I will just draw it out right here So let's say this our graph right here. A log is basically like that. It's like that Actually Yeah, that's what a log is. You know, I was thinking of a squirt or square root square roots More like that. It's more like a parabola. This is more like Steeper, I guess where it flattens out faster. That makes sense. That's what a log is If you know what it is, you don't understand then I would I would look that up Reward this one will be lower because of how much currency we're gonna get so make sure these rewards are kind of balanced So you will have to experiment with this. So what I'm gonna do is Do I'm literally just gonna Divide this by two I guess Or divide this by yeah, since it's like production you want to spam click I'm gonna make this divide by five Okay, so we're gonna set all these texts real quick So our event text and we are going to do something cool We're going to do public idle tutorial game Game and what we're gonna do here is Set our event tokens text dot text is equal to game dot data So we are accessing our data right here. All right instead of doing public player data game player data and then Like this public player data instead of doing it here We're this is creating a brand new copy of this. All right and since this Our main Class right here is mono behavior. We are able to drag that in okay, so we'll use refer off of here What we can do is create a var a temporary or not a temporary, but we'll just do Data we can set that equal to game dot data. So what this does here is that it creates? It sets this temporary variable Which is if we do player data right here instead of our Player data equals game data We are setting this data's reference to our main one right here the one that we use for our game Like that makes sense Like whatever you see in here is data We are accessing and then here we can just change that to var since it already knows what variable it is Where variable type so we can do now instead of writing game dot data every single time We can just do data dot Event tokens and then we need a format that how do we do that? We'll do this event tokens Okay, and then we will do Format it just as so and I'm gonna create a big double real quick I'm gonna put this at the top public big double Toe event token boost and now you can do this however you want, but I'm just gonna do data Should we got to do ETH dot data because we don't have this var this variable right here So we'll just type that's game Dot data dot event tokens divided by a hundred now obviously you can make this a Log or square root or you can make it linear or exponential however you like And then we're gonna add our boost right here And this will be another curly braces to put our variable in here. Don't forget the dollar sign. That's very important and Also, we can add our Notation so we can do game dots What is our notation? I forgot What what do we use for our notation? It's notation method. Is this private? I believe so Yep, so make sure you make this notation method public if you want to use it somewhere else Save that We can do game dot notation method and we are able to convert this scientific notation And we can do the same thing here now. Why are we getting it error? It's because we need our comma F2 to determine. We only want two decimals and actually for Tokens you can make it zero or you can make it F zero if you wanted to But since we are being rewarded in dust like we're getting a fractions of event points We're just gonna do F2. We want to see those extra decimals All right Now You got a lot to do. This is not a simple process We're gonna add some more variables to manage our Events, so we're gonna do public rule event active All right, and we want to be able to display our reward. I guess so what we can do here is add At the top you can do public game object Event reward pop up Okay and We can add We want to determine which one is active. So we will do event active id We will give monday would be one Tuesday will be two etc Okay, so this is a tricky part. I kind of don't exactly remember how I format this So I am looking at my events script to get this perfect. So we need to determine the The date so we can do that by public string. We can actually this is a variable We could make this a method if we want it to We might let's see see how this turns out. So this will be day of the week. It's a string We're just gonna do a method all right So now the reason this is gonna be a little different from what I'm doing it on my end is that I actually grab a date from the server And I actually grab it from a global api to make sure everyone's on the same events So if you want to do that you can figure you can learn on my uh You can learn on some like like my leaderboard tutorial on how to use api or you can just search up how to use Unity web requests. I really Don't feel like attempting to get this to work to get into the networking stuff. I want to stay this non wi-fi related Or local I guess what we can say So what we can do here is we can return Um Let's create a new date time date time dot our date time dt is equal to Date time dot now and what we can return that is date time or a dt day of the week Dot two string So now what this does is that day of the week is Um just a string it returns what what date is so monday tuesday wednesday Etc All right, and it's also returns that's capitalized. So we have monday or Tuesday stuff like that cool Now in here we want to manage what days we're going to do all right, so back All right, so i'm back. We need to do a few things before I forget because I looked over my script again I'm like, oh my god. I would have forgotten this Let's make that a var because we can We need to add a public string Previous Day checked because we need to check to see if it actually changes, right? And we can do this by Am I doing on start? This is one of the ways to do it We will make sure our event active is set to false We want not be starting any events even though by default it's it's false And we want to set our previous day checked is equal to the previous is equal to day Excuse me Day of the week Cool, this can be marked private All right, and then now events we will do the exact same thing After all of this code at the very bottom We will make sure to check for the previous day at every frame. So if um This is different then which we'll do eventually Then a date that we will check later on in the code and then it will trigger that new event system All right, so the first thing we need to do Is to make sure to reset these all the time So if previous day checked is not equal to day of the week And event active Then we need to make sure we disable them. All right, so we can do I'm trying to think I think I should have added I think I should add a bull here. We're not a bull. All right public bull Event active we already have event active though This might get a little confusing Basically, I'm trying to make a series of bulls to just to determine which event is Okay, you know what screw that we're not going to do that We're going to do event active id We're going to set that to zero and we want to make sure so we'll do four int I equals zero I is less than So we only have two events. So we need to check this twice Okay, now for you since you if you have seven events, you are going to do this seven times instead starting at index zero Okay, and we can We can we can okay something I forgot to add here Actually, do we already have it? I think it's the cooldown time. Yeah, we already do that. Perfecto we will do data event cooldown at index i Is equal to zero Okay, we're basically resetting it once they do it and now we're going to add a protection thing Let's see. Let's see these events are five minutes long. We're going to make it so they can't join if it's five away five minutes away from Uh start i'm going to attempt to do that if I don't end up doing it Then you can scream at me scream and agony In the comment sections below you can literally just like Crypto crowds added Six all right Uh All right, let's get started. So now we need to run individual events So we can add a switch case here and we will do event Um Day of the week. No, this is day of the week day of the week Cool So now we're going to do case Monday remember what we're doing monday and tuesday. We are going to do public i'm going to add public void run event Run event ui and we're going to do int id here And this will be run event ui This will be This will be one because our inactive is zero and now we can do negative one and start from zero But I rather day one to be monday that makes sense So this might look a little confusing, but just be aware of what the difference between What zero means for the id and what it means for the arrays. Okay Hopefully that makes sense if not Ask me below and I will clarify Tuesday Will be run event Id to if you aren't subscribed make sure you subscribe Maybe like the video if you enjoy the video That would mean so much to me All right, that's all we got to do for this and then we can just manage the rest of the ui here So now we're going to add another switch case here. This will be an id And our case is one And there's a lot of switch case going action going on here Uh, what we can do is I totally forgot we actually have two game objects. We have the unlocked and But not we have the unlocked one. So we want to make sure these game objects are not Shown so events unlocked. All right, that's and we're going to create that new array. So I have seven as usual And we're going to do case one We're going to do if Event active id is equal to one There is equal to id Basically, it's one Then we are going to do events unlocked game Oh events Unlocked id game object dot set active true cool Cool cool cool cool cool And uh, let's see. We're just going to do a bunch of this tech stuff Uh, so here This will be pretty much our active stuff. Sorry. Hopefully this is not too confusing. I am trying my hardest not to be confusing Events id dot game object dot set active true We only want to show the events that are actually Like inactive. All right, and we're only going to do ui stuff here. This is for optimization purposes Okay So here we're going to do four int i equals zero i is less than two i plus plus Now we're going to set all of these to false and then we're going to set the one I set events i To false and id to true because we want all of them except this except the one that's active right now to be enabled that makes sense Okay Now I think we can actually do some stuff Cool and we might not even need this switch statement after all Yeah, it doesn't look like it. So we have the reward text. So let's get rid of this. Why is it doing this? Cool, so if reward text i Or id sorry dot text Uh, we are going to do plus Blah event tokens. So that would be plus Our event reward id space event tokens cool And I'm just inverting inverting this if statement here. So basically it won't run any of this If the event for that id is inactive Okay, and honestly pretty much it will be because we are only running Uh Actually never mind scratch what I was going to say. I was thinking of something else. Okay So now we need our currency text So now my currencies are the same. So this is where you might need to Determine what currency using so by using a switch statement. So if id is equal to one You can do the currency text equal this way Or this way, but since mine are the same I'm just going to do it all in one. Okay So the currency text is going to be equal to dollar sign. Get out of there dollar sign currencies id crypto grounds Cool Uh, now our cost text Cost text Id that text is going to be equal to so now we haven't done any of the cost related stuff But I'm going to make an equation For these so we're going to have our public Big double again these probably shouldn't be big doubles It depends on how big your numbers are going these should probably be floats because our numbers are not going high at all But we're going to do big double just because I can But I still prefer floats, you know, let's do float. Yeah, whatever. I'm doing big double. I can't make up my mind Uh, this will be our cost Equals new big double seven public big double This should be the ends. So this is the one I'll do ends int levels equals new int seven Cool So now this will simply be dollar sign cost curly braces cost id at index id All right, so the start text is going to be a little complex Oh The first thing we need to do we also need to make coins Be based on an equation And I'm honestly going to make them the same so for int I equals zero I less than two so I'll go to a maximum of one i plus plus I'm going to do cost i I'm going to make this far too. It's going to be equal to 10 times big double dot pow I'm going to do 1.15 to the power of levels id There we go. We got a basic equation I All right So now our start text is going to be based on different things It's going to have a cool down and it's going to be all that good stuff So what we can do Ah, I'm trying to think Okay, I see how we're going to do this So basically here Our start text That text is going to be equal to So if event uh id is equal to zero And Uh data. No, we got to do eth dot data eth dot data No, not eth. Sorry game dot data Game dot data We can also make another var up here. Let's do that var data is equal to game dot data so If I if the current one is zero and data dot cool down Is Greater than zero question mark ID throughout the id Oh, right If you're out to know right event cool down at id index index id is greater than zero Then we are going to display that cool down Okay So honestly, this is probably going to work better in a diff statement in our favor So we're going to do that if event active id Is equal to zero Then we can check So if our Our start text If you will do the question mark operator here Okay So if it is and Uh, so if it's greater than we'll display our time here colon start event Okay cool So we need to display this cool down specifically and I will pull that up date time So I'm going to be completely honest I don't exactly remember how to do this Okay, I see how we're going to do this Okay, so we're going to do var time is equal to time span Dot from seconds And we have to put in a double but we can put in a float. So we're going to do that data dot event cool down id and how this works Is that this formats into Like, uh, I believe it's an it's an enum Where you have date or you have days hours minutes seconds Or it's a class or it's it's an object. I don't remember but basically that's how it's organized So how we can do that Is by doing Time dot to two string at sign. I don't exactly know what at sign does. I'm going to be completely honest This is how I did it There might be a better way than this So Let's say we want hours. We're going to do hh backslash colon mm backslash colon ss So let's say we have hours for a cool down, which we're going to do six We're going to do We're going to do an hour or two hours. We'll do that So we have our start text that should work Now we need to have else if it's something else if it's active Now we could flip this I believe No, it doesn't ask us to do okay. That's odd. All right Otherwise our start text will equal So if the cool down is greater than zero So No, that would make sense Wow, if it's already in one We don't need this question mark operator We're going to do exit event because we want to exit early. Okay All right. I think our ui is officially finished cool So let's just keep going. We need to do the start that the completion the exits So let's start the start. So this will actually be a public void toggle event into id We'll see if we need this. Let's do var data dot game data equals game dot data Hopefully I'm not going too fast or I'm going too slow I'm just trying to do this in an efficient way better way than I do it for my system too Maybe we'll see how it turns out. Um Okay, so now we need to check If the event active id is equal to zero and our cool down our data dot cool down at id Is greater than is less than or equal than zero if so Okay, so another thing. Oh, so this will be our start. So this will actually be our start Now else this will be our Exit. Okay. Otherwise if it is active then we got to turn it off, right So we'll send we'll start with the the exit first. So if that Active id will be set to zero We will set our cool down To two hours, which is 6400 seconds Okay And we have to reward our players too So we're going to do data dot event tokens plus equals reward at id perfecto And We can reset all of this right now to if we want to so we can do currencies at Id is equal to zero You can do levels at id Is equal to zero and that honestly should be good. I think that's yep. That's the only things we need to reset We actually remember hopefully aren't skipping I just pulled a stupid mistake But we actually have to do the reward first before the reset or else if we reset the currencies stuff Then we will our reward will be set to zero because once we access Uh Once we access our reward, it will be zero. Okay Okay So just make sure you're paying attention to all that I think that is it for our exit For our start We're going to set events active id to id We are going to We're going to use the same cooldown Okay, I see how this uh, we'll try this. I don't exactly know if this is going to work We're going to do data dot event cooldown Id equals we're going to do five minutes What is that 300 seconds? Okay That should work We are going to reset this stuff just in case Just in case. All right That should work That is our start Another thing we need to do is to make sure the players don't start like immediately. So we're going to do and Shoot uh, uh, I have never done this before so Let's try this now Date time Can we do that? Yeah, I didn't think we could so we're going to create a temporary Date time now equals new Equals date time dot now so and date time dot Okay, so this is going to be a little complicated, but we're going to do something here. We're going to put this in parentheses, so if now dot hour Is equal to let's see Hour if hour is equal to 23 And Now dot minute is equal to 59 Uh, so our event's actually so okay, so I see And now dot minute is equal to Is greater than or equal than 55 Okay, that should work. So basically we're checking it if it's at 23rd hour, which is An hour before like the next event the next day And the minute is greater or equal than 55 so that's five minutes away Or exact or less than the next day or to the next hour pretty much Then we're not going to we're going to make sure this is false. So but we do that by putting the explanation mark Saying that as long as it's not five minutes till the next day. This event is safe to run. Okay cool I should add that to my game now Took me a bit to like kind of think that out even though it's something so simple Cool. Cool. Cool. Cool. All right. So now we're going to do another method public void Complete event and now ironically we already did that. That's what this is right here complete event Var data equals game dot data int id Cool We have our complete event. Therefore we could replace it here. All right You can make that price it to perfecto Very easy very easy So we have our start an exit our completes and we have our a our ui done We need to actually do the game itself so I think these are yeah, never mind. I was going to say they should be Internal methods to make for the buttons. I forgot it's got to actually On the outside of the public method so We're going to do public void So we have two clicks. So now make sure you have A method that fits accordingly to each one now since I have two clicks both do the exact same thing I'm just going to make one method for the click Click with an int id and we're going to do a switch case Which in really we have an array. We don't need to do that So Now we are going to get our currencies our currencies I plus equal to plus. I know this is id Plus equal that was equal Uh one so that's for basics So now the thing here is that the second event is production in the first one to click So this is actually where some you know switch statement comes into play So switch id So if our event Is zero we're going to do now. We're going to do One for monday. So we're going to do one for monday. So if it's monday Then we are going to add the click times levels id And honestly to see it's safer to say Currencies one plus equals one, but it doesn't make it do it's same thing You can do id or one for both and actually we can get rid of this one times and just do levels uh Levels plus one Because this will be zero because levels is zero by default for us now for case two We aren't upgrading that at all So i'm just going to make this id So this one will just be Currencies id plus one Break that is it. That is all this Click is So now Okay, so for Tuesday, we have a production upgrade, right? So we're going to run our stuff here. I guess we can say or we can have a private void run event Int id and actually before I forget I want to run this event id in certain cases if Honestly, this is most of the I this is actually it's just this one. So if the data dot event No, it's just game game dot events group Dot game object. I've did this in the previous episode Dot active self is true. We're going to run this We're going to do the exact same thing here Now we're only doing it for this run event UI because we want the UI to run only for on that page Everything else can be run in the background if we're not looking at it So here we're going to add a switch case now. We don't need any run events for The first one So we're only going to do this for Case two all right So if case two We are basically going to do currencies id plus equals levels id Times time dot delta time. Of course, you're probably gonna have a lot more than me So make sure that you kind of understand why I'm doing this here. So now we're going to go back to here We're going to do run event Two and this is remember. There's no curly braces here This means that only this line is applied to this. So this right here is the exact same thing as this I remember that okay, this is just much cleaner And yeah, so we have our run events outside of this and we don't need anything here And I honestly believe that is it Oh, no jokes on me. That's actually not it Um Okay, we have to actually do the cooldown too so if event active id equals zero And Okay, so we'll just do that right Okay So this is actually gonna be we're gonna autocomplete this event. I forgot. This is how we do it So where am I calling this? Oh right there. Cool. Okay. So if event active id and Game dot data So this is actually where we should do Okay, so we're gonna have to do this in a for loop int i equals zero Oh I have a good idea I could make this Okay I am going off to different branches. We're gonna do public int current day Okay, so I'm gonna leave this here. I have a good idea So you can expand on this But if it's monday, we're going to return one return two awesome sauce Otherwise return zero cool So we will do this for if event id equals zero And game data dot event cooldown for the active day Is greater than zero Then we are going to subtract that we're gonna count down this timer is time dot delta time uh else if If event active id is not equal to zero And we're still gonna count down right here else One more else if now this can probably be simplified and I'm just not thinking straight Now if this timer is less than or equal to zero We're gonna do complete event current day Now again, don't forget to add on to this if you have more days Okay, or more events. So this is just how my system works. So yours might be completely different from mine Okay, so if you just have one event you Do it manually doesn't make sure you kind of just get this management, right? Otherwise, I believe this is it This is a lot of stuff. So I am expecting errors. I am expecting mistakes We will see about that Yeah, it looks like no even error. I don't think so Cool. So this is what the arrays look like So also another thing you can change the size here too. That's pretty cool So our events is zero because I'm an idiot and I deleted it and then I saved it And then I added seven so make sure we change our size to seven here That should work Very cool. Thank you unity for letting us be able to do that Because if we start it shouldn't reset if it does then we need to do that in the start method So we need to drag our game manager into here our event tokens right here Uh, oh shoot our event reward pop up I'm sure you guys know how to do this But I guess we can do it anyways So on event complete, we are just going to do event pop up game object that's set active true And then we are going to do public void close event reward And that will be game object set active false And also we need one more text Public text event reward text This will be a far pop up And again, you can be unique to your variables. I hope you are doing that We're going to set this text to text equals plus Dollar sign I'm gonna do here reward Oh shoot. We actually need to do that above We need to do this here before the reset make sure you're paying attention to that or else you're gonna see zeros And you're gonna be commenting on my videos. Why am I seeing zero make sure you do it before it resets? Okay, it goes along for any of this kind of stuff Cool, we will make that UI real quick. We're gonna make a game object reward It's gonna be a very basic one Because this video is already long enough I'm gonna have a button Its color will be the backdrop And the reward will say close make that white here Going to make this bold plus zero We need to have more text Event tokens Cool Lots of the last minute changes. I have faith that this is gonna work Very boring pop-up that will work for now. Also before we're in here Let's drag our event manager into the click button and we are going to set this as event manager close event reward Cool, and then here we're gonna do the same thing. So for our production. Oh shoot. We forgot to do actual buy methods Oh, man Uh, shoot That's not good That's not good Okay, so this we're going to just create one method because we have our same the same levels And this should be pretty easy. This will be just public void buy. This will be int id And basically we're going to check if levels No, no, no, no, no, no If currencies id is greater equal than cost id at index id Then we are going to levels Levels plus no, no, no, no We're still going to do levels id plus plus We but we need to subtract the cost first currencies minus equals cost id And that should work One more last minute change and I think we're good to go So what I do to make my life easier is to select all of our buttons We need to add in all of these and what we're going to do is just drag the event manager and then go to the clicks event manager click And then now this one is One and two so our first button will be one for monday and two for tuesday and the click upgrade Will be buy Event manager buy so the first one will be one and the second one will be two Okay, we are done with our buttons We can close board two Cool, we can honestly turn off that as well and also our events button We wanted to change that achievement sex to events For the events button only and we can go back to main screen Now let's finish adding this stuff So our reward. I mean you actually go back to here So we have our text right here, which is our reward from the pop-up And now our events we only have two just remember that okay So I could literally change the two if I want to but we only have two So I'm only going to drag into so our events we have monday and tuesday And our events unlocked will be for the monday one and tuesday. We're done with those for me at least And then we have our reward for the first one our reward for the second one And our currencies currency for monday currency from tuesday And now we have our costs so That will be from here So actually what I did wrong is that I have this here. So let's go back So I did wrong is that this is all in the same one. So we're going to create another text And just put that in half Gain plus one cg per second anchor that to the bottom And this will be our cost text. So this will be our cost And this will be our label and this will be our cost We're going to do the exact same thing for monday We're going to anchor that to the top you can even this out however you want Just as so I'm going to copy and paste this for click upgrade Except we're going to change the the label to improve creation one Hoping this won't look Stupid. Let's test that here actually Yeah, that'll look just fine Okay And we can remove this old text here. Let's go back to our event manager. Hopefully you understood that Basically, we're going to get the cost from there and cost from tuesday And start text is our start buttons Text for monday text for tuesday And our award that is it. We are done now. We just got to cross our fingers For one, it's it's sunday. So we're gonna have to do some debugging here. I'll show you how to do that Let's just see what happens Yeah, so right now it loads tuesday, which is not correct Oh, wait, we forgot our pop up here Surprised we didn't get an error for that Okay, we gotta close that because it's not so it's just loading that by default So we can close event screen event manager award. So how can we do this? So let's go to where we get the day of week. Can I do yesterday? Yesterday? No So what we'll do here is return day of week. We need to set this back by one We can do dt day Day Day is equal to so monday. I am guessing day for monday is zero. I'm guessing that's how they do it. Let's see Oh, it's day of week, okay Okay, so I'm gonna do day of week minus equals two Does that work? Okay, we'll just do dt day minus. Why does it not work? Has no setter. What the what? You know No No, it's not right. No. No, no, no, no, no How did I do this? Okay I see how I did this Okay, that is actually weird Okay All right. Well We're gonna do this. I'm gonna copy this from here because We're gonna do this We're gonna set dt equal to this right here. So now We're gonna actually do datetime dot now dot year Replace this stuff with me We're gonna do the same thing for month And the same thing for day But since it's sunday we need to test for monday So we're going to do day plus one. Okay This should work cross my fingers If it doesn't then I'm dumb. That's for sure Now make sure you save your project because we did a lot of hard work Cross my fingers. Ah What did we do? What did we do? For our game manager, we totally forgot to add our events canvas Nope, not that's this one right here. So make sure you drag that save. So if you have a Uh, an unassigned reference exemption, that's pretty much what it means. So we're going to daily events Cool We're on tuesday Why are we on tuesday? I don't know Is it tuesday? Let's try this. Let's do without this plus one We're gonna try some debugging if this doesn't work Then I don't know Uh, what's the boost? Also, we need to add a plus one to this boost too. I totally forgot plus one And we need to add an x here. So it looks like we actually have a boost cool And now I on actually I totally forgot to okay. So this boost right here We need to go back to our main script here Okay, so we're going to go to public event manager Event now what we can do here are events. We'll just do events. So what we can do here Is go to where our gems boost is so we're just going to go search up gem Gem boost We're going to do times gem boost. We need to see where that is Data dot gems boost right here. So whenever we multiply our prestige It's most likely we're going to want to do events too. So we'll just do events dot event token time or event boost and multiply by that And we're going to do the same thing in there. We're going to add this here too. I think this is all of it Yep, uh, perfect. Alrighty That works, uh For a click we can actually add this to coins click value Or multiply it as well Perfect. We're good to go. All right. I am crossing my fingers. So this doesn't work. I'm gonna cry. Did we change the date? I am positive. Yeah, we did. Okay, cool. All right. Let's try this. See if it's monday, if not, then If we're out to drag the events in here My mia Okay, so now events So now there is none because it's sunday So that was really strange on how it didn't do that before so we're gonna do plus one again and cross our fingers We're gonna get monday If not, then we're doing something wrong with the the code. Okay, we're still getting tuesday Why? I don't know. Let's check this out So that's the run events. What about the run event UI? Uh, we're gonna debug or id. We're gonna see where we are going with this Now i'm going to pause the video here and i'll explain what i'm gonna do. Okay Okay So I found the issue is that we were actually doing id one and two so I forgot We actually have to do zero and one here. That's right because we're doing the zero index So that is exactly why that is happening And I think i'm going to screw up most of this current day Cool down. So yeah, all of this current day stuff. We needed to subtract it by one Or actually for current day, we can just do return zero and one So this just kind of got mixed up with our one and ones and twos So this can stay because that doesn't really happen in midcode This all should be fine Hopefully we'll cross our fingers and if something's up, we will fix that So after this saves and after we save we can run this game Okay, all right. We have our Monday event looks like we are ready to get started. So let's start event Oh funny thing. I forgot to actually I forgot to do the actual start button because now it goes to upgrades All right, so make sure you drag your event manager and do event manager Start and Yeah, we should be good to go on that one All right Daily events start Why? Okay, so it looks like nothing's like interacting with this Okay, so I got the issue fixed So basically what I had to do is go to my run event UI and I had to change the for loop to this The reason why I was doing this because it was constantly every frame Or not every frame, but every time it ran through it was constantly flickering like you can't see it But it was flickering between True and false because remember when we disabled it and then we re-enabled it because it just keeps switching very fast So then that was just not stable. So basically I just added an if statements that basically if i is equal to the id We're just going to make it true while the rest from our false. So if our current active So basically we're just saying the current game object The current event to game object to true the rest of our false Um, so now the next issue is the button the start button is still not working So obviously it's calling it But I do not know why it's not starting it. So we're going to go to toggle Uh, oh wait a minute start. We're start. Okay. I am really stupid I assigned it to start which is like the unity start method. We need to set it to toggle events So make sure this one is So what is this one one? And the second one is two So remember we're only doing one and two for the stuff that is involved with the event active id Honestly, I should have made it negative one instead of zero and that would have made it a lot less confusing But that was my that was my bad Just know this should work Oh, we got 10 minutes. All right Uh start Oh Okay Okay All right, so I guess we already have a cool down. I'm guessing that's from the save system So let's go to our data Our vent cooldowns. Okay. Yeah, see we've already started this cooldown So we're gonna set this to one second and now we should be able to start. Let's try This is very interesting indeed I believe it's because our buttons are one and two So the solution to fix this the official solution. I promise this is the official solution We're gonna make Var so we're gonna change to we're gonna make var id equals id Var id two equals id Minus one because we are going to grab every single Index so this is one two Actually, this one's fine. This one we can do plus one. So this is actually id while the rest of these indexes right here We got to do minus one Because these are zero based in a complete event Same thing here So this should work. This honestly should work if this doesn't work. I'm gonna cry myself to sleep All right, let's give this one shot ready Ah rats Also, the time is wrong It's not 6400. It's actually 7200 Okay, yeah, so make sure that's 7200 because that's actually two hours. So why are we getting why is it ending right off the bat? Okay, so I think I know the main reason why this is not working The reason why it's not letting us do this challenge is simply because it's one minute till the next day So I guess for now. We just got to wait So I know we know that works, but it just doesn't work properly So the thing we got to do here is not just to complete the event automatically We got to actually like do this. So we're gonna do else if Else if this is true, we're just going to Ignore or literally just gonna continue what you do that by We're just gonna return else We're going to complete the event. So that shouldn't happen and now we should be able to do this Hopefully hopefully all right If this doesn't work, then I really don't understand because that's there's only one way I can get to the complete event and that was from that method. So we'll check that out So now it should be Tuesday event See the time thing works. We got to test two things In one situation. So where's run it? Okay, I see now our we need to make the the pop-up not show up And the time is not even correct either So we're gonna set this to one All right, let's start it So the event started text is not updating. This is not a good sign So our event active id is two Looks like we didn't need this event active bull. Why is this not working now? Nothing's working Is it updating? Oh, it's updating. So it looks like the ui is not updating. Okay, so that's an issue So none of this ui is updating and I don't know why So we're actually gonna have to complete events because honestly we want the uh, Let's actually pass down a bull bull x if x We're gonna display this pop-up And this is false. So we don't need that and we're gonna go back to the other one display true because we just completed the Uh, this one. Oh wait, we actually don't want to do that My apologies All right, so we're going to add here is another else if statements. So basically we're gonna add If else if Is greater than zero. We're just gonna return it because we don't want to see that reward because that doesn't make any sense Or you just like remove this Okay, so what we can actually do is just add a A semi colon just to determine an empty statement. So basically we're not doing anything here We I mean we could add this elf it like could do elf if and make sure these are both false We could do that too, but I'm just gonna do this because I already did it Um, so our next issue is related to the UI. None of the stuff is actually updating. So where is our currency so here's our currency So event active id So We might have to change this too zero one Okay, so here's another issue. We're we're running into the same situation as before We actually need to create another id too Is equal to this is this is like the whole issue. I should have been consistent This is completely my fault. And if you guys are confused at this part, I somewhat understand. I'm very sorry This is all my fault Uh id minus one my apologies No, no that can't be right I think it's just this right here I think this is good So events active id plus one, so I think that's literally the only thing we have to do So we have that what else do we have to do? We have the timer So I think that's it and the whole thing is good to go. I'm pretty sure From based from my analysis. So let's just clear that and we'll give it another go We'll have to reset our timers too. Oh the vents still going. That's not good. That's not good So the event cooldown is saving and uh, yeah, we should do that Start event So that's the issues that the cooldown is technically still going So I think we might have to say okay. So the issue here is that the cooldown is still going So we need to fix that So what we're gonna do is Add this event active id to our Our player data and then by default we're gonna set this to zero So now we're gonna get a bunch of errors here because we need to access it from data dot on start what we're gonna do is if Uh, actually this what we're gonna do here is change the start method to start Events and what we're gonna do is run this in our main script Right after we load our data because we don't want to cut we don't want to Risk having the merge thing where we access the variable Before it actually loads because that can happen So make sure you add the events dot start events in your Start method in the main script or wherever your game runs Um, so for here we're gonna do game data dot event id if it's not equal to zero Then we need to Set it equal to zero and we need to reset that our timer We're gonna do that for all of them just because who knows Or what we could do actually this is Not much easier. We can do game dot data dot event cooldown equals new Flute Seven basically we're just clearing all of it. We are resetting it from scratch and creating a new Um, a brand new array All right Cool. Cool. Cool. That should work We're getting a budget. Ah, right. I forgot gotta fix all these first data dot data dot data dot game Dot. Nope. I already have a data data dot data dot data dot data dot data dot All right, fix all those errors All right, we should be good to go. I'm very done with this. This is why I don't want to get into the multiplayer stuff This is already enough All right, so we should be good. Looks like the timer's still running though. Why is this such an issue? Okay, that's why because it's a false And this is currently our cooldown. So we're just gonna the ui still not going why? All right started anyways Okay, so our cost updates our event is live Our ui is still not updating unbelievable. Well, we got our exit events But it's not exiting. Oh my god That is so frustrating That is so frustrating Okay, so what I'm doing here to make the exit work We need to add this at and data events active equals or id equals zero So we need to make sure we're actually not in a an event. Otherwise We will just cancel it. So we're gonna add that to both of these So this is the very weird setup, I'm not satisfied with it for sure it can definitely be simplified, but I'm Not I'm not like too focused on it. I just want to get the actual issue done Now we got to fix the actual ui again because for some reason it's still not updating properly Okay, so I see the problem here. It's actually adding to a different Born right here. So let's press exit. Let's see what happens. Ah, it still says exit. Why we create still? The fence is not active our event Yeah, it looks like it recent but the ui is just such an issue right now. I don't know why I think that's it's because of this right here Yeah, we need to have this start text not at the bottom. So that's one issue The other issue is that we're adding to the wrong one The wrong index so click here. We have one and two, right? Why am I doing that? It's zero one So that's that's the same thing for the buy. It's just completely messing up our stuff So what we're going to do here like we should be doing Properly, we're going to go back to our click in production or our bio stuff We're going to change our number. So the first one should be zero First upgrade should be zero and the second ones for both should be one And that should fix everything. I am guessing it doesn't but we'll see how it goes Cool, we got our countdown ready to go. It doesn't do anything on start correctomundo Yeah, this become this just requires lots of testing in order to actually get this right So we're going to set this to one seconds and we should go start our event But yeah, let's go Okay, there we go. We have our events. We can clean stuff up Cool We can upgrade Get more So actually I just noticed something. It's actually upgrading the click instead of per second For the events. That's an issue But we have our correct amounts. So if we do exit that we should get some event tokens cool We got our event tokens and it should be boosting everything else when we start this again It's supposed to clear this but it didn't I think I know why we're going to do start event And uh, yep, it resets it. We're gonna do exits and we should get our tokens again. So we know that part works But to fix that issue we need to do actually we did the same thing for the buy It's the actual reset thing. I think that we screwed up on because when we toggle the event We set the actual event ID. Oh, we do event ID minus one Okay, I see That's a bit weird, isn't it? Isn't that weird? That's a bit weird. I think That's that's odd very odd Uh, yeah, this does everything correctly. It just doesn't want to reset. I guess Okay, that's fine as long as we know it resets on start then I think we should be fine with that Uh, what else are we having issues with? Um, text display. Yes. So we can do here we can do game.notation method around that add f2 And obviously we want to add that everything to the rest of the UI. So we'll just go up to our run events at UI And yeah, we will add all this stuff Another thing that isn't working is the per second stuff Don't know why But we'll we'll check that out I think it's something to do with the run event So we actually need to change just the one There we go But I still don't understand why we're actually adding on to the click when we shouldn't be so let's go to our click So our click is Zero and one right so we need to change this zero and one That should be fixed So make sure you change the right numbers you're gonna I know this is probably the most unorganized video I have ever made I deeply apologize for that But I would restart but I did so much this video So if you guys honestly need more help and comments then I completely understand that All right, let's give this a shot Get 10 There we go. We get one per second And we get one per click Perfecto So now we should add the timer to the exit event. So we're just gonna let this run We're gonna get some event tokens So let's let that run while we do that so we can go back to our UI Uh method right here and for exit events. We can also add a dollar sign So let's add this var time to the outside because we're gonna use this for other cases Uh dollar sign exit exit events. We're gonna add Timer here And we're gonna do the exact same thing time to string etc So this will be our time remaining and also we can since that we are in a braces in the braces format like this We can use a format specifier like this. This can only be done in here. You cannot do it right here All right Now we can save let's exit event Cool And now you see we have our timer for our event and it should work. So let's give it two seconds perfect This is our event system and it finally works Anyway guys, thank you for watching this video. I hope you guys watched all of it and Understood everything all the madness I did and if you didn't make sure you go back like pay close attention I jump back and forth a lot. So yeah, just be careful with that if you guys have any concerns makes you um Drop your comments and concerns and problems and issues all that and the comments below anyways If you enjoyed this video, please subscribe if you aren't already and drop a like and turn on the bell Anyways, thank you guys. Have a good day. All right. Peace