 Hello guys, Crypto Grounds here. Welcome back to another Unity anti-marriage mentions video this episode 11 and today We're gonna be working on challenges. If you enjoyed this video, if you learned something new, make sure you smash the like button Subscribe to my channel if you knew Turn on notifications for future live streams and videos and comment all your feedback questions all that good stuff below Anyways, let's get on with it. Also, don't forget to watch the very end It really helps the channel grow and the video get exposed to more people anyways So challenges I kind of forgot about this. I think I was supposed to do it before infinity Because when you start the game you start a challenge one, right? Which is to do a big crunch. So that's the one you're currently at And when you infinity for the first time, that's pretty much or not infinity, but big crunch That's pretty much when you complete challenge one. So we kind of forgot one of the the basic fundamentals So let's finally do that. So I want this to be kind of a short and sweet video and um I'm also like really tired today. I've had A hockey practice six in the morning with one hour sleep and I just kidnapped so I'm really tired So I'm gonna try to make it not too long. So anyways, I'm gonna create this challenge interface. I will be right back Okay, so we have our challenge one right here. Also, what's weird is that Heavy never really labels which challenges which and I mean like obviously this challenge one two three four I still just like to see challenge one. I don't know. That's just something I like to see I just yeah, obviously this is challenge one This is challenge six. I mean, it's pretty obvious But I'm I added challenge one at the top just because I like it like that So I made a new button. I made a new Um empty game object here Um, I added the exit challenge button And so far we have challenge one because this video is going to be challenge one only Just to get the idea of it because once we get the first one done The rest of them are pretty easy as well Except we just got to do some of the modifier stuff So we're just going to start with that All right, so let's take a look at the interface real quick. So we have the start button And the completed right so it looks like this And if we start on another one, I believe they all turn red Oh, no Okay Since when could you Switch challenges? Is this the same warning? Oh, it is. So, okay, that's weird. I didn't know you could switch challenges. That's a bit weird Um, okay, so I guess we can do that too Um, but for now this button just turns um Hmm The thing is that I can't just make this green actually I could I can make it light green I guess Yeah, he has his buttons really weird where he can change the center of it and I can't really do that So anyways, no no big deal. So we need to create a new script. So we're going to create a new empty Game object first called challenge manager. I remember this is the normal challenges I'll probably do separate for separate scripts for infinity challenges and eternity challenges, etc All right, create a new script called challenge manager Create an ad All right, I am inside my challenge manager and I have added four namespaces to the beginning Uh, you need the engine dot ui tm pro break infinity and the static break infinity epic double This is pretty much all we'll need for our challenges. We might need system system.collection is not generic, but I'm not sure yet um Possibly not I might use arrays instead for this one and because so if you're curious on why I'm not using prefabs, um It's because we're only adjusting one thing right just the button So I I mean I could make a challenge start button prefab, but I think that'd be just be kind of silly I mean, there are only 12 challenges and I'm just gonna I could just drag them in manually and Do that I just think it's just a little easier to do because we're gonna have to search inside each Children Because we're have to make like a challenge prefab here with the challenge script And then a challenge start button. So basically it's going to look for every single Um, it's the exact same we do for the achievement, right? We have our Row and then our achievement here, right? We also have a row script and we also have an achievement script We got to look through all the rows if it's a row and it has an achievement inside that which is like one of these right here So it's just I just feel like it's unnecessary All right, so I'm just going to start with the list of images because that's pretty much what it is And this is only going to be like a very single. Um, just a one index For now because we only have one challenge. We're going to call this challenge start buttons Okay And pretty easy And I also wanted to find two colors here. So I'm just going to copy and paste this one here wants done importing Okay, so currently I'm grabbing the values for the screen right here And I'm going to make a new color variable here With the fault with the with this stuff right here All right now I'm going to make another variable called Complete green and I'm simply just going to set the green to one just to make it a little brighter and for it to pop Oh, yeah, we actually have to change two things. I forgot. So we got to change the the start text Um, okay, we actually have another color here. This is gray. So I'm just going to make this one Uh, let's let's snatch that real quick. See what that looks like Oh, it looks like that. Okay I'm going to grab this color too and make another gray variable. All right, and we also need a new array for our tmp text All right, we'll call that challenge start text and we need a Um, I think we need a start method because of our like initiation with the rays and stuff We're going to do for our or a list for our challenge completions And we also need a public void update method. Okay Um Alrighty, all right. So this is going to work pretty much the exact same way as achievements and the infinity upgrades We're going to look we're going to create a list You know at the start We're going to set a temporary variable to the count and if there's an error such as like a null reference or Index or like it doesn't exist pretty much and then we will catch it and create a new list like that So let's head to our data class and let's do that. Okay, so we are currently in our data Let's uh, create a new region called challenges And in here we're going to create um We're just going to create one list Okay, yeah, we're going to create one list actually we're yeah one list. That's fine It'll be a bull list to determine how many times we completed this one now when it comes to The Yeah, eternity challenges where we can complete them multiple times We won't be using a bull list anymore. Okay, so What am I doing? This is called the challenge Completed. Yep Okay, now in our constructor, we're going to be doing the exact same thing. We're going to do create list Uh, we're type bull and it's going to be a size 12 we got 12 challenges, right Yeah, we got 12 challenges. Okay And we're good here. Oh, yeah, we also need a current challenge state so we can um Save and load what challenge we're in So we're just going to create an int actually int. Yeah, we're going to create int Current challenge. Okay, and this will determine so negative one or actually we'll set the zero So if it's zero then we're not in any challenge, but if we're in Uh challenge one, which is by default Then we're going to do all the challenge one stuff, which is nothing Okay So i'm also in the constructor I'm going to set current challenge to one because at the start you start with challenge one active. You just don't see it All right, so back in our challenge manager, we're going to create a try catch And ignore that. Okay, so now we're going to set our Um, oh, yeah, we need we might need our our game Uh our game object Um, so at the start we're going to do var data equals game.data And then in the try we're going to call We're going to make a temporary variable We're going to do absolutely nothing with and call data And challenge is completed Uh, okay Oh, yeah dot counts. We want to return the count. Okay, and if we get an error then we're going to To recreate it in here, so we basically just grab this right here From the data and replace it with the following Uh Proper variables. Oh, yeah, we also have to do capital data because it's static. It's a static method Same thing as achievements. Okay So if it's a if we get an error, then we just recreate this list and problem solved All right, so let's do some of the interface now So let's create a data Uh variable here of our data equals game.data And a for loop var i is equal to zero And semi colon i is less than now instead of just putting 12 we only have one challenge So we're just going to start with one But however, I don't really want to change that every time we add a new challenge So i'm just going to do challenge start buttons dot count. Okay, and we will adjust this once or dot length And we'll adjust this once we keep adding more Okay, I'll put i plus plus Now you could either do the start text Or the start buttons doesn't really matter Okay, and now we're just going to access the We're going to access the color. So just challenge start buttons at index i Dot color is equal to Uh now we have three different colors. So we need to determine if it's running or not. So what we're going to do is uh if We're going to create a question mark operator So data dot challenge our current challenge Now we're going to see if it's equal to i plus one because we're running the for loop as index zero But our challenges are going to be in index one So we start from one while for the for loop we start at zero and that's how it goes for arrays So we're going to see if the current challenge. Oh, sorry. I meant minus one. Sorry So let's see the current challenge is minus i minus one. Okay. So let's say we start at zero And our current challenge is one. Okay. So we need to do um No, I was right. It's i plus one. So zero plus one. That's one. So if the current challenge is one And i is zero because we add it by one Then the challenge is currently being run. So we're going to set this color to running gray. Okay Otherwise, we need to determine whether if it's incomplete or complete Okay, so we can do that by doing data dot challenge completed At index i Dot oh, yeah And then we'll have another question mark operator and if it's been completed then we're going to set it to complete green Okay, otherwise we're going to set it to incomplete green And we don't need to put parentheses around it But if you want to just stay organized like that then you then you can just whatever you want Like that Alrighty, and we're done with that And it's exactly the same thing for our text. So we're just going to copy and paste this because it's really the same format Uh, just replace the start button with the start text And we we are accessing the text instead Okay, so now instead of running gray complete green incomplete green We need to change these to strings. So we have running. So if the challenge is The current challenge is the one that's selected. Then we're going to do running. We're going to set as running Otherwise if it's completed, then we're going to Display complete it and it's not then we're going to display start. It wants again very easy same Uh structure as that Okay, so now we need to actually like start the challenge So we're going to create an empty void method called start challenge And it's going to take in an integer so int id And we're going to do we're going to check some things So we want to make sure to not start a challenge that's already been completed And one that's not running. Oh wait, can you actually restart? Hold on that's that's that's weird That's stupid heavy Why would you do that? Why would you allow that? Well, I'm gonna block it off unless there's a valid reason like uh restarting the challenge I don't want to risk that Yeah, I don't see why there's why you can switch so you can switch that's reasonable but why Why the why restart when clicking on when you can just do exit and then start Like that just seems like a little safety precaution because there, you know, someone could just click on this without Uh confirmations on and then actually start it. But anyways, we're just gonna we're just gonna prevent that All right, so we're gonna do that by basically checking to see if id is equal to data dot Oh, yeah, we need to create that variable that data variable of our data equals game dot data So if data dot current challenges, so if id is equal to data dot current challenge, then we're just gonna return it Okay, we don't want to just switch it right But we also want to see if it's active. Okay, because we want to end this current one So let me think how we're gonna do that Okay, actually, I don't think we need to check for any of them because it's we're basically just performing the same thing We're just doing a challenge reset and an infinity. We're basically just doing an infinity just without gaining anything Um, actually I want to see do we get I'm I think we do I'm trying to see if we start a challenge. Do we get infinity points if we can Oh, we don't have break infinity. So that kind of doesn't matter Okay, yeah, we're just gonna do an infinity without gaining anything All right, so in our big crunch reset. I'm basically just going to Uh, let's see. When do we actually call this? Only that, okay Well um Where is it? Oh and infinity points is right here. Oh, that's good then Okay, so we're basically just going to call the big crunch reset in our challenges So that kind of just saves us a lot of typing or copy and pasting And simply all you need to do is just set the the current challenge equal to id And we need to call the big crunch reset which is in our infinity manager And honestly that's in game. So I don't want to create a whole new object Just the access it wants so I can just do game dot infinity manager Oh, wait, is it actually in there? Maybe Okay, where is our infinity manager being accessed? Nowhere, I guess so I guess we're gonna have to So at the top add your infinity manager Uh infinity manager Okay, and down here we're going to do infinity manager dot big crunch Yes And that basically just start the challenge without giving us any um Infinity points, which is nice. I am smart that I actually put the infinity points in the In this right here instead of adding it to the big crunch reset method cool All right, so now we have a star challenge, but we need to determine one to complete a challenge Okay, so we're going to do this in our update method as well And just like the achievements right here, we're going to create here. Actually, let's grab this achievement manager here We're going to be doing the exact same thing as like the unlock achievement, right? Okay, so we're going to create a new method called complete cheat challenge Uh into id and we're going to be doing the exact same thing Uh, let's see So basically we just set the the complete to true and just return the user interface That's also another thing. I could just update this ui less often. So I might change this uh in the meantime as well So in our complete challenge method, all we got to do is set game dot data dot challenge completed at index id is equal to true and that's it This is very easy. We also I'm not I'm not going to convert this into an expression body like this because We will probably add our update ui here So we're going to do that And now we need to check for our challenge completion. So for the first challenge And we're just going to start with the first challenge only We look for it reach infinity for the first time And I believe that's the same thing for all of them by buying a dimension automatically erases all lower tier Yeah, so basically all of them are just big reach big crunch and that's it Okay, that's pretty easy. Um, also now that I actually think about it The challenge Just the challenge and after I'm trying to think when do we actually end the challenge? Maybe it's a big crunch reset I don't know. Let's just do it in here and we can experiment with that All right, so if So if data dot anti-matter is greater than or equal to double dot max value And Oh, so we're gonna check three things. We're gonna check the anti-matter the current the current challenge Make sure it's equal to one And we need to check to see if we've already completed the challenge. So we need to Uh, we don't need to create a new method new method like we did already like, um, yeah, we just never mind um We also need to do uh Data like to uh, challenge completed at index Zero and we want to make sure it's false to be at the explanation mark at the beginning Otherwise if all this is true, then we do complete challenge. I didn't uh, Uh, ID is zero. Okay, so that's our argument zero And that's it. We pretty much do the exact same thing for all of them This might I'm not so like as we add more this might just become an update challenge checker Where because this is pretty much like we just look for the current challenge, right? And then yeah, because None of these challenges have a A smaller requirement for what I'm from what I remember and from what I can see It's all big crunch. So I really don't think we needed to check for this 12 times And yeah, okay, so I'm trying to think does it so we have like you are currently in a challenge. I think right No, I thought at the top it said you are currently in challenge. Maybe that's ng plus three. I'm not sure But I think we're done. Oh wait canceling challenges Yeah, I want to do cancel challenge real quick And that's actually it's in the same method. I was about to start um Writing something so I'm gonna change this method called toggle challenge because we're basically just going to toggle between challenges and Oh, so instead of returning if the current one is Wait a minute. Oh, wait a minute. No, that's exit challenge. Never mind Never mind. I have that right. I thought clicking on this would exit, but I forgot that I was like heavy Why would you be able to restart without exiting? I don't know So anyways, let's just make that cancel challenge method at int actually, no, not even an int id And we're pretty much just going to set the current challenge equal to zero That's that's literally it and we're going to update the interface Yeah game.data Yep like that So are there three cases where we can update the ui starting a challenge canceling a challenge Completing a challenge. Oh, yeah fourth starting like you're just like the very start of the game So i'm just going to make a method for this uh public void updates challenge Ui and we don't need to split this up like we did in the achievements where we did rows and Individual achievements, right? We just kind of separate it like this All right, and now we now we can call this update challenge ui at the very end of each of these methods start start challenge Cancel challenge and complete challenge cool And now we can test. All right, so don't forget to apply your buttons here So the start button is going to have access to the challenge manager And we are going to uh do start challenge That's our method and we're going to select ideas one right Yeah Excuse me. Yeah, that's right. Okay now our challenge manager. We need to drag in our game controller our infinity manager And our start buttons. So we only have one right now. So i'm just going to set the index i'm just going to set the size to one Once again, we will expand once we have one challenges One more thing I forgot to do is the actual interface for um challenge Okay, so What we need to do is add a canvas for our challenges public canvas challenge canvas Okay, and we're going to go back to the bottom and Add this to our navigate method. So challenge Yeah, challenge canvas dot game object dot set active false And in here, we're just going to add a copy and paste this and replace the the case with challenge challenges And just replace this infinity canvas with challenge canvas. All right, so now we can switch between challenges and all the other stuff Okay, so in our game controller, we need to drag our challenge canvas right here And I'm just going to test this by closing all the other stuff and let's give it a run Also, don't forget to save. I forgot to save. It's very crucial. All right, we already have a null reference. What's wrong? challenge start buttons And might be this length here Oh, wait, huh? Uh, what's wrong here? This object is not set What is it talking about though? I'm guessing it's the challenge completed, but I that doesn't make any sense though Let's see. Let's flip the start text on the button and see if it does that Yeah, I'm gonna experiment. So I figured this out All right, I think I see the issue here. So it is related to challenge completed. I think it's because of the start method Um, we don't have to do this in a This doesn't happen in achievements because we have a start achievements method. So let's create Let's replace this with a start challenges. I kind of always forgot that I got to do that And now we bring this into our game controller And we also have to add our challenge manager at the top challenge manager Okay, and our start method right under the achievements are under this data equals saves as this loading part right here We do, uh Challenge manager dot Challenge manager. Wow. I don't even like it Uh, challenge manager dot start challenges. Okay And it should fix all of our issues. I think that that happens because when we Unfortunately and we're just kind of unlucky with this It runs starts before we even get to this right here So it does all of this before we even load the data just somehow. Okay. I'm guessing it's just like an order thing Like challenge manager comes before a game controller Just because of alphabetical order and that's just how you need to manage it. I don't know That's my guess. Oh, we're still getting no reference Oh, right. We forgot to add our challenge manager to our game controller. Duh All right, so it looks like we're safe now so we can finally oh So it looks like challenge is still Toggles infinity instead. So don't forget to change this label from uh infinity to Challenges and the challenge button Cool, so we can now start. Uh, we also forgot to apply this exit button, but um, no big deal right now I'm just gonna temporarily set that Actually, let's do that outside. All right, so exit challenge. We'll set that to exit challenge Exit, where is it? Is it cancel challenge cancel challenge one of the whatever I called it? All right, the game seems kind of broken right now, doesn't it or is it because of the upgrades? I don't know but the game seems like paused okay never mind. I guess it's not All right, so currently we are not a challenge one just because of that's just not how it worked so what I'm gonna do is I'm gonna start it and then I'm gonna Uh, delete the save from the file location and then see if it starts as challenge one. So let's start the challenge one Oh Okay, that's interesting Okay, so we why is the alpha one? Okay, I'm not really sure why the alpha is set to zero So I guess I'm just gonna set all of these to one I'm not really sure why that's happening honestly, but it does say running. So at least we're starting challenge one But now let's let's give ourselves infinity Wherever data is okay. Yeah, let's give ourselves infinity real quick And do a big crunch Oh, so this is we're running in challenge one. Is that true? Current challenge one. So it looks like that the it didn't work Okay, while we got to fix that Well, I just realized that I accidentally put Stupid me. I accidentally put the challenge completion stuff inside Um, the challenge UI instead. That's that's okay That's my fault. All right. So now it should properly work All right. So so should we yep or oh, why is that button still dark? I don't understand Why? I don't know why it's doing that. That's a little weird If I if I complete this challenge, I bet it's gonna go back, right? Let's just see. Let's just see this Oh, man, it does, but we didn't even complete the challenge Well, that's not good Uh, all right. So my guess is that for some reason the colors just not initial initializing Uh at the start even though this running gray. Okay. Why is running gray like that? That's weird I'm just guessing because we created this variable and we loaded it and all that stuff and then it just Didn't save all this stuff. So Like the usual painful stuff you gotta do this in the star method. Unfortunately. That's just how it is I don't know. It's this fixes itself on compile when you compile. So like built for Like built for your project. I believe that's my guess It's because it just doesn't auto compile Um old stuff, I guess I don't know I'm not really sure why it does that but it's a really weird issue But I guess that solves that issue because if you set that up to alpha one, it would fix it Now the next issue is why is challenge completion? Uh, that's not working. All right So a good way to check for this is to do prints and just copy and paste all three of these statements and and see if they're all true And if it is then it's related to our a complete challenge method If it's not then it's related to our if statements something related to the current challenge itself and maybe this too Okay, so looks like we fixed this right here Um, so yeah, okay good. So false true false. So what's false? Um, yeah, so that's that's right. So this is false. It says that challenge zero is already completed Right, that's what it looks like Um, this might be an actual previous issue Where's our challenge completed right here? So it says it's already completed. That looks like okay, so let me try that again um Honestly, I should just get rid of that requirement here because I mean, we're not going to be checking for it Anyway, since we're not going to be going back to current challenge one so I Okay, let's just try this Ah, so it says it's running. Okay. Why? Okay, so it's got to be this right here Okay, and also, I think we forgot to exit this challenge when we complete it So I think that's also another part of the issue is that we have to Um set current challenge equal to zero that so we don't have to actually reset anything We just got to set this current challenge to zero. So it doesn't do that What I could probably do is for loop it. Actually, no, that's a little bit That's a bit um much work that we don't need to do Okay, so now we should be able to complete this Cool. So now this is completed Okay, so, uh, have I tested the exit challenge yet? Oh, I canceled challenge. So no Okay, so I guess we're running it again. So that's the issue We're not it keeps running the previous challenge because I guess this is a good chance to test our exit challenge Cool. That works. Just is fine Um, so I start challenge. We want to also make sure ID Oh, yeah, we want to do data that challenge completed right here So if data doc challenge completed at index id is true, then we're going to return it We don't want to restart a challenge that we've already completed Okay, so now we know all that stuff works Um, I wanted to test one thing right. I wanted the chest to see if A full resetting works. I'm not really full resetting but um Deleting all the save stuff and seeing if we start. Oh I don't even know what that was. Okay. Um But I want to see if it works where we can just start with challenge one Okay, cool. We start with challenge one running and now if we Where is my data right here? And now if we big crunch for challenges and we complete it nice Very nice We just need to do the auto buyers next after all the challenges and yeah We should be good to go Anyway guys, if you enjoyed this video and if you learned something new make sure you please smash the like button Comment something below comment whatever you'd like Subscribe to my channel if you're new and turn on notification for future videos and live streams If you watch the entire video you are a hero and I love you very much. Thank you guys for the support lately I know I've been an inactive not as active, but I've been trying I've been trying to make videos as much as I can and yeah I've been very busy with crypto clickers and other stuff. Anyways, I'll catch you guys on the next one. Peace