 Okay. Oh, wait, it actually loaded. Okay, so yeah, it worked. Okay. Hello, guys, Cryptogrounds here. Welcome back to another Unity C-Sharp Auto Game video. This is Episode 37. Today we're going to be doing daily events. Okay. So what we're going to do is we're going to cycle through seven different events. Okay, there we go. We're going to cycle through seven different events. Okay. And we're going to do this based on a UTC server time. So this is not locally, this is based on like a server so people can't time cheat. And I'll kind of get more into this later on in the series. I plan on doing like a preventing time cheating. So that'll be nice once we get to that. Okay, so we're just going to add some UI real quick. Okay, so I've made a basic user interface here. Basically, it's just a game object with seven different days. And you can have it reward whatever you want. But for me, I'm just going to do gems. And I'm going to make it so it's based off of whatever amount we have. So for example, 1%, 2%, 3%, 4%, 5%, 10%, and maybe 25% for day seven, as that one would be the best. And yeah, so we can also add a little icon here. I don't know. I'm just going to make it really simple, because I'm not going to spend time designing a logo or an icon. So I'm just going to like label that as D or something like that, something basic. Okay, so we have like a D right there for daily rewards. And basically, it'll automatically show up, I guess. And if you want to just view the rewards again, then you could just press that D. And claiming it will close it as well. All right. So so we can also have a pop up thing that says you have claimed this amount. So let's have another game object. Let's copy this daily reward claimed. Okay. And we'll just get rid of all this except for that one. And we'll just use as info as a reward text. Okay, notice look like that. Cool. And we'll just get rid of this. Cool. Okay, so now we need to code this daily rewards thing. So we're going to create a new and empty game object in your scripts. Let's just call this daily rewards. No, daily reward. And then we'll make a new script called daily reward manager. Okay, so first thing we need to be able to check when this happens. I'm just going to get rid of this and copy and paste you import the using use the you need the engine UI interface interface. I meant namespace. Sorry. Okay. So we have our time API thing here, which is this. And basically, we access the time by creating a method, we're going to call or it's going to be a co routine. As this is the way the one way I think we can do this. So we're going to create, sorry, if I'm like, talking poorly today, I'm tired. And I got my, you know, I got my retainers in again. Okay, so we're just going to get you to see time, because basically what we're going to do here, we need to get the global you see time not based on your current device or else people can time cheat. So we're going to create a temporary unity web request variable. Okay, and we're going to do dot get. So basically, we're going to get some information from this link right here. HTTPS colon slash slash forward slash twice world time API dot org slash API slash time zone slash etc slash utc slash. Alright, there's the link right there. You zoom in. Okay. Okay, so now what we're going to do here is yield, return requests dot send web requests. Okay, so now what's the difference between yield return and why why can't we just do this right here. So basically what yield return does it basically just pauses the code, not your tire code, but pauses this class and until we get a result from request dot send request. Okay. And now we need to check to make sure some errors occur. So we're going to do request dot is HTTPS error or request dot. I think it just I think just error. No, it's network error. Okay, so if we get any form of error from this from this call right here, this method call right here, this send web request, then we're just going to simply ignore. Okay. Else. So basically, just do add an explanation mark. So basically, if we get no error. Okay. Then we need to grab this information. So the format this is in is an adjacent array. So this is we do request dot. I think it's some kind of handler, download handler dot text. Okay. So now our information is in a format of string. So if we go to this right here, you'll see I'm not going to show it because it has like your access API in it, but it'll show a bunch of information like date time and stuff like that. That's, that's this, that's this right here. Okay, this JSON. Okay, so it's in a JSON array. Okay, so now we need to create a string right here or a date time, which we will do public date time UTC time. Okay. So this is more of like a temporary access point for now, because we're going to eventually move this to the player data because we're going to save this. So we're going to set UTC time equal to JSON utility from JSON with a type of string. Okay. I think it's capital string. Yeah, I think that's it. Okay. And then in here we do JSON. And then we do to date time, right? I think it's convert dot to date time. Yeah, it's convert dot to date time. And then end that with that. So basically what we do is we use Unity's JSON utility to convert this JSON string into a specified type, which is our string right here. And then we are a string. And then we convert that string to a date time, which we set that equal to UTC time. So now we have a date time right here that we can access. And there's nothing else we need to do in here. So we can just what we can do here is invert this. So now basically, if there's an error, we're going to do yield break, which basically just ignores all this and just ends the co routine from there. Okay. So where are we going to call this? So we need to have a public void start. Okay. And we will call a start will start new coroutine. So start coroutine, get UTC time. Okay. And we'll also call this every like, minute or so, public void, update, get UTC time. Okay, so now I'm going to add a timer, a temporary timer, public float, UTC timer. And I'm just going to add this by time dot delta time. Okay, so now let's make a new statements. And let's say we want this to happen every 30 seconds. So this is happening, this is going to happen at the very end of the update method. So I'm going to do if update timer, or if UTC timer is less than 60, we're just going to return it. Otherwise, we will start a coroutine. Okay. Also, we need to reset this back to zero after we start this coroutine. Let's do it right here. Okay. So now this every 60 seconds, it will update this time. All right. So we need to somehow create a UTC time for this. Okay, so let's move this to our player data. Okay, so let's see where's a good spot for this. And this is compatible with our new save system. So I'm just going to do our region daily rewards. We need a few variables here while we're at it. So public current day. We need a public date time. UTC time. And I think that's it. Okay. It's a hashtag and region. Let me zoom in here. Okay. And now let's copy this into our full reset or now our player data constructor. And let's see we're gonna set current day equal to zero. One. So that's the first day. Actually, let's just set it to zero. And our date time is going to be set to date time dot UTC now. Okay, cool. So by default, it should be set already, hopefully. And also let's. Yeah, that I think that should be okay. Let's set current day to one. I want to see if it says zero or one. Okay, now we need to access this in here, which we will create a public or an access point public idle tutorial game game. And then we will do game dot data dot UTC time. Alrighty. So now this time is being saved in here. Okay. So I have an idea. Actually, I have an idea. Let's create a temporary date time to make this easier. Temp date time. Okay. So let's just set this to temp date time in here. And then we will set game dot data dot UTC UTC time is equal to date time temp date time. Okay. So what we want to do here is that we want to be able to compare these together. Okay, before we actually set these equal to each other. So let's do an if statement after we check for this. If game dot data dot UTC time dot day is not equal to temp date time dot day. Okay. Then we are going to trigger the reward trigger the reward. Okay. Now, let's say the player is gone for more than a month and for some reason they come back in exactly a month later. We that's an issue here. So what we can do here is put some parentheses around here and do and oops and this more parentheses. Okay. So if the day so okay. Yeah. So we're going to check for the day, the month and the year. Okay. Because we don't want them to come back in exactly a year later. Like one of the chances we just don't want that to happen. So that'd be kind of weird. We want the worst case scenario. Okay. Is this fixed? I think it is. Yeah. Okay. So basically, we can do it. Okay. Let's enter this. Okay. So basically, if the dame dame, the day, month and year are all different, then it will trigger this reward. Okay. And after the fact, we will do game dot data dot utc time is equal to temp date time. All right. We need to trigger this reward. So let's create a bull here. This is going to be in our daily rewards. So this is going to be daily reward ready. Okay. I forgot to create it. So let's go back to the top right here in our daily rewards region and do and make this a public bull daily reward ready. Okay. So if this is true, then we're going to set game data dot daily reward ready equal to true. And also we can create a temporary variable called data and set it equal to game dot data and replace game dot right here and game dot here just to shorten things up. Oh yeah, same for here. Okay. So now this is ready, we need to update this interface. So let's create some UI. So we have a public game object, daily reward. Okay. So if daily reward, no, if data dot daily, oh, I forgot, create that variable again, var data equals game dot data. If data dot daily reward ready is equal to true. And we're going to set daily reward. Or we're going to do daily reward dot game object dot set active true. We're going to enable that. Okay. Okay, let's finish this user interface. We need to create a text array for all the texts. Actually, we need to create two of them. So this will be the day actually, no, we just need one. This will be the reward. Okay. And we can also create the images too. So public text array reward text is equal to new text array size of seven. And a public image component or image array. I'm just reward button goes new image array size seven. Okay, so now here we're just going to be adjusting the color. We also need some. So we're going to control this in here. So our current day is zero. So that would be we want to set this once. And we also want to be able to check this too. Okay. Okay, so I'm going to create a bull called you'd see time checked. Okay. And that will go in here. We're also going to add another statement. And you to see time checked is false. This is for the sake of it happening once. So which means we can bring this into our update instead. I was like, what happened to this? I think we don't need I think we can get rid of this. All right. Mm hmm. Okay. Well, this is now. Okay, I see. I want this to happen. Every 60 seconds. I'm going to set this timer. Okay, let's bring that like this public void start. I want to set this timer. UTC timer. Wow. It is equal to let's say 59 seconds. So we'll just have a one second delay. But I want this to occur every 60 seconds. And that means we can bring this timer out of here and get rid of this. Okay. Got a lot going on here. But basically, we're just doing this time check thing every minute you can reduce this to six minutes hour or whatever you want. So we're going to set reward. So let's see what is what is our current day or current day zero. So let's just set that on claim. Okay, yeah, current day is going to be one. Okay, I see what we're doing. So let's create a for loop now. I'm crazy. I'm creating the the user interface like the claimed things we know which ones we can actually do. So if I is less than seven, we'll add I by one. Okay, so reward text at index I dot text is equal to we also need to create a reward. So this will be a simple int array. So if I'm jumping around a lot, I'm trying to create this at the same time, and know what I'm doing and hoping this works. And this will be our reward percents. And this will be a size seven array. And we can actually pre define this in start. So let's just do, let's get rid of this. Let's put this in start. And this is going to equal new int array. And we probably get rid of that. We'll see. Let's see the percents are 123451025. Okay, yeah, we can get rid of this int. Okay, so in here, by default, it's going to say plus, let's see, our data gems to get. Oh, wait, gems to get. Okay, so our gems to get divided by our percent. Okay. No, it's our percent divided by 100. Or reward percents times. Okay, I see what we're doing here. Okay, so we're gonna multiply this by the reward percents and do reward percents at index I divided by 100. Okay, so now this will basically just reward is based off of this percent now. And we need to add gems. And then semi colon. Okay, so we need to make sure this replaces with claimed if it's already true, or if we already have it. So how can we do this? So we're going to do if data dot current day. So let's say a current day is one. That means we haven't claimed it yet. Okay. Okay. No, our current day is zero. That I'm very confusing myself. Okay, so let's just stick with current day one. All right, let's set current day to zero. Okay, so since current day is equal to zero, that means we haven't claimed anything yet. So if current day is equal to I plus one, or so for now, if it's, let's say it's one, if I plus one, that's two. So if current day is two, two, or less than two, no. Okay, I see, we're mixing up these operations here. So if I is less than current day, I think that's plus one. So if our current day is zero, we haven't got anything yet, right? So if we do plus one, well, zero is less than one, I think it's just that. So I is zero. I think maybe it's minus one. Okay, let me try to draw this out. Okay, so basically what we're looping through this at zero, one, two, three, four, five, six. Okay, so we have our rewards here. Let's say our, our reward, let's see, see is our current day. So this will be true or false, like if it's displaying or not. So if current day is zero, zero, okay. So then zero is not less than zero. So that's false. If it's one, then zero is less than one, which is true. So our reward day is zero. Yeah, yeah, I think that makes sense. Yeah, okay, I think that works. Okay, so it's just if I is less than equal than this. Okay. So here we can do question mark operator. And what we can do is if I is less than data that current day question mark, then we will have claimed instead of our reward. Okay, and we can always test this and mess around with this too. Same thing with the reward button, except we're just changing the color at a naked eye dot color. And we're doing the exact same thing here. So it's going to be equal to if I is less than data that current day, color, it's going to be color dot green. Otherwise, it's going to be color dot white. Okay, that should work. Okay, so now we need to have a claim method. So we're going to do public void claim. And this will be an int i or int id. Okay, so let's see, we should be able to claim any of the previous ones. No, no, we shouldn't know it's based on that current day. Okay, so if data dot game dot data dot daily reward ready is true. Okay, so if it's ready, then we're going to just add current day add var data because we're using this numerous times. Okay, we can get rid of this game dot. Alright, so if it's true, then if we are ready to claim, then we can add the current day by one. And we will set this ready to false. Also, when do we set this checked? Actually, I don't think we need this check anymore. Now that I think about it. I think, okay, let's get rid of this bull right here. I think we need it. So we're going to only check it if it's false. Okay. Okay. So now we need to add this reward. So let's do data dot gems. Plus equals whatever this is right here. This is our reward. And our I instead is our current day. So since our original current day zero, right? No, yeah, it's yeah. Okay, I see why this at the top and it'll be current day right here. Data current day. Okay. Now it should add to our gems based on this percent array right here. And it should trigger this stuff here. Okay, so I'm going to add another game object. This will be public game object daily reward claim. Okay, and this will simply just show up after we get our reward. And we need a close reward to or this will just be close rewards. Okay, so this will close both of our game object in our daily reward. Yeah. Okay. And we also need a public void toggle rewards, because we have that. Oh, yeah, we have another thing right here. We need to toggle our rewards in here. So we're just going to set daily reward. We're going to set that active to the opposite of daily reward dot game object dot active self. All right. And now in here before I forget, if this is true already, we can claim this reward, then we're going to set this game object to true. Okay, I think that's the last of it. I personally don't think there's anything else to do. All right, so now in unity, we need to drag a few things we need to drag our game manager into the game slot, our daily reward game object and our daily reward claimed game object. And we need to get all of our texts and our buttons. Okay. So we have day one, two, three, four, five, six, seven. We also, oh, yeah, that's the right one. Okay. And four hour and this and this text right here is our reward. I should have labeled it. So this is one, two, three, four, shoot, four, five. What happened? What was that five? What was that three, four, five, six. Okay, there we go. Yep. So now for each of these buttons, we're going to add a button component that will activate this click. Okay, so then add that click on the plus drag this, this not the game manager, the daily reward manager. And this will be the claim. Okay, so now we need to assign it in forever single one of these. Also, wait, I just realized. Okay, I forgot we don't do anything with ID here. Okay. So we're going to do if ID is less than. Well, yeah, if it's equal than current day, so if this is zero, if it's basically if it's less than or equal than current day, data dot current day, right. Yeah, that makes sense. Okay. And this should be based on our ID. Okay, cool, cool, cool. So make sure you add that less than statement or else it won't really track the reward. It'll basically just kind of assume that well, this number would have just been useless in the first place. Okay. What else do I have to do? I think we just have to do this toggle. This D this is the daily reward button. Okay, so I'm going to add a button component to this as well. Click the plus drag daily reward game object, go to daily reward manager and do close or no, this is toggle toggle rewards. And this will show up. And this will be our close button. Okay, another button component, plus daily reward, daily reward manager, and then close rewards, right? Yeah, it's close rewards. Okay, cool. This should work. We could just toggle both of these. So now the really, really the main thing I'm kind of worried about is this. Where is it? Okay, I guess it doesn't show date times here. It's the date time and the current day. Let's see what does it set equal to? And I think it has to be zero, obviously. Oh, yeah, okay. Let's see. Oh, okay. That's an issue. String was not recognized as a valid date time. Oh, okay, I see the reason why this is because it's an array still. Okay. So I really don't want to show all of this. But basically, see how this is like, you know, oh, wait, this is not an array. What? Okay, I see what we have to do. We have to actually create this object because this is labeled as date time. Here, I'll show you real quick. See how it's labeled date time right here? We have to create that. Okay, so let's, let's make an object right here, a class called, I don't know, it could just be you see time, it could be named whatever you want. And in here, we need to create a string called date time. And this needs to be marked as serializable. Okay, so now what we can do finally is to convert that to date time JSON utility from JSON, instead of a string, it's UTC time. Okay, because that's what this is. Or what and go boy, what this is right here. Okay, should work. And basically, I'm just going to convert this to a date time anyway. So yeah, hope they'll work. All right, let's run it. What's this invalid cast is not valid. Or specified cast is not valid. Okay, so I'm guessing it's because we need to create an actual okay, good, good, good. We need to create a public UTC time UTC time. Okay, this is the variable we need to create an object variable. We set it equal to JSON utility. We need to set it's equal to this. Okay. And this is basically just a string. What we can do here. So let's see, we have our temporary, right? Temporary, yeah, temp date time. What we'll do is set this equal to UTC time dot date time and do convert dots to date time. There we go. That should work. I mean, it should work. I'm not sure why it can't just directly. I don't know. That's probably because it's just it's trying to convert a UTC date time into a date time, which is like not that's not what it is. Okay, so we haven't gotten there. So I'm guessing this is working. Oh, yeah, I need to change these dates. The text isn't working now. That's, that's not good. Oh, oh, I see this. Okay. We need to have a separate if daily reward dot game object dot active self. Then we're going to run this for loop. Oh, that's what this right here. Okay. We can get rid of this if statements we already set that equal to here. We don't need to spam it, you know, we can just have the person be able to close it. Okay, so let's get out of that. I don't want to test the reward yet. I want to see if the text actually works. So the thing is that we have zero gems. So I think I'll have to add like a little base thing. Yeah, see, it's based on zero gems now. Okay. So we also also another thing I forgot is methods dot notation method, notation method. Yeah, don't forget that notation method. It's going to be very important. So it's actually now I just noticed it's based on gems to get it should be based on your current gems plus 100. Okay. Now why do I say plus 100? It's because if you have zero gems, then the daily reward is completely useless, right? So we want to kind of have that base, a base reward. So now it's just plus 100. Do we need to put parentheses? I don't think so. Oh, we do. Okay. So yeah, put the parentheses around this or also mess up the equation in general. Instead, it'll multiply this percent to 100 only and not gems and then gems will be added afterwards. And that's more than what you're supposed to have. Okay, so now we should get our reward here. It should be around 10. Oh, so this is zero. What's the trouble here? So it's I think it's reward per sense. No, it can't be that. Because if we do, okay, so let's do the math here. So if we do 100 times one divided by 100, I think it's casting. That's an issue. That's just one. Okay. So now what if the reward was 25% should just be 25, right? Yeah. So I think it's something to do with our casting. It's rounding up. It's okay. So the reason why is because this is an int. So when we do one divided by 100, obviously, it's going to be a zero because it's rounding down because it's an int. So we need to are actually I can't remember if it's, if it cuts off the decimal of it rounds down, I don't remember. It's one of those, but it's the reward zero. So clearly it's rounding down to zero because it's an int. We don't it doesn't have any decimals. So we can we cast that to a float. Yeah, there we go. We have a reward now. Cool. So let's claim. So let's see if we tried day two, it should not work if you try one. It doesn't work either. Okay, well, cool. At least we got the display working. Let's fix the text itself, though. This text needs to be purple, whatever this purple is. Okay, so let's replace all these days or quick. Okay. So another thing I'm kind of trying to figure out is if this is like not claiming at all. Because the problem is that it's saving this time as current as the current day, even though we didn't like claim it right before, at least. So I feel like we need to it's because these days are equal after a few runs eventually. So that means this this is set to false. Right. So now we aren't able to claim that's a big no no. I think we should only set UTC time to temp date time. Okay. After we claim. Okay. After we claim. Does that make sense? I think it does. Okay. So now we can't adjust this. We need to what I'm going to do is something I'm going to reset. Actually, I can just do a full reset. Okay, let me do a full reset real quick. Can we do day one? No, we cannot. Okay. I think we need to wait another 60 seconds. I think that's what we're waiting on. Okay. What's the issue here? That's okay. I think I might have to create two strings. Okay. Oh, wait, it actually loaded. Okay. So yeah, it worked. Okay. So it took a load. What? Interesting. So now these days are on sync. Okay. So if we update this, what's this? UTC time? So now UTC time is this day permanently until we claim again. Okay. So we got our, so it didn't add to gym. Why didn't add to gyms? What the heck? What's the problem here? Oh, right. I forgot. We have to cast this as a float to inside the claim section. So we should have gone our reward, but it also said plus 1000. So we forgot to assign our reward text. So let's add that real quick. So our public text reward claim text, whatever you want to name it. And let's have our update. If daily reward claimed dot game object dot active self, then we're going to set reward claim text equal to this right here. And this is now so this is going to be the current day. Uh, you know what, let's actually set it equal in here in claim. So we do ID, right? Yeah. Okay. Just replace it with this. I don't know what's going on here, but let's do that. Oh, I see. So we need to do, we need to have we need to convert this into a string, which we're just going to do methods dots notation method comma f two for two decimals. Okay, what else are we doing wrong? Oh, right here. Okay. So now we're setting this reward claim text to uh, to our reward after after we claim, sorry, I'm trying to figure out why I'm doing bad. Okay. So plus this gems. Okay. There we go. Dollar sign plus curly braces methods on notation method, our reward comma f two for two decimals, curly brace gems. Okay. So that should work and we don't need a troubleshoot because I've already cleaned my daily reward for today. Anyways, if you enjoyed this video, also, I hope this works. So if something goes wrong, please let me know in the comments below. I'll be sure to check that out. So anyways, if you enjoyed this video, make sure you smash that like button, subscribe to my channel. If you knew everything would mean a lot to me, the like comments, subscriptions, notifications on all of that. Anyways, check out the videos in the top right corner. And also we're still two, two patrons away from the anti-myo dimension series. So if you want to help out, make sure you tune in. Thank you for watching. Peace.