 Hey guys, what is up crypto grunts here welcome back to another idle game tutorial video This is episode 16 and today we'll be making an infinite Achievement a system. Alright, so if you haven't subscribed here if you're new make sure you hit that subscribe button turn on the bell So you get notifications whenever I upload and hit a like if you enjoy this video And I just get started with it So this is my second time making this video my first try was not so good I ran into a lot of problems, so I'm going to be going through this tutorial again So you guys don't see the first time, but this will be my second time talking about this So this things look a little different So first of all we need to make Two things and achievement button and our own achievement screen to see all the achievements All right, so I already have an achievement button here So you just create another button like usual And I'm just gonna drag that up here and then we're gonna create a new achievement screen So I have one right here, but I'm gonna create one from scratch so you guys can see me do that So I'm gonna hide this main screen by going to our canvas group typing zero and turning these things off So we're gonna create an empty And we're gonna name it achievement screen Okay, it should be dead in the center right there. And now let's make it to the sides of our canvas Make sure you anchor it so it stretches to our canvas as well or our screen All right, so in here we're gonna create We're gonna create another empty object create empty. We're gonna call this an achievement And what we're doing right now, we're gonna create an achievement prefab to make our lives a lot easier, okay? So it should be about the size Make the size of my buttons here so it kind of matches That All right, and now I'm not I don't want to copy these but so here what I have Can I do that? Okay, yeah, so basically what I want you to do is to create a title text I want you to create a progress bar and I want you to create a progress text to show you how far you are into the achievements And it should look like that so we can move stuff around or click and that looks good All right, and then I'm gonna put these all into my achievements. I can delete my old thing All right, so I have the script here. I'm gonna delete this Okay, so what we're gonna make what we're gonna do is we're gonna create a script for our achievement All right, so we're gonna create a script called achievements Create an ad oh My apologies this script is supposed to belong into the achievement up here not the progress bar So make sure when you create it it's in the achievement. So in this case, we can just drag our achievement script to here All right, let's open that up First things first we need to add our properties in this achievements, which should be self-explanatory. We don't need these two We need using unity engine dot UI All right, so in here we have a text a text and a progress bar, which is an image So we have two texts. So the first one is going to be a public text title We also have the text another text public text progress And we also have an image for fill Which is our progress bar All right, so that script is done Once that saves what we got to do next is drag our title into the title our progress bar Into here into the fill and our progress into here And this is the progress bar on top Let that how you set it up And next we're going to drag this achievement into a new folder called prefabs, which I've already created So just drag it in there and it should create as a prefab very nice We can rename these as well if we'd like So I can just rename that to achievement one and let's create another one. So we're going to have two achievements All right, we can rename that to achievement two Move that down and we don't need to change these texts because work our script is going to handle that Make sure you save and now let's head back to our main script All right, so in here we're going to start from our player data. So since we have two achievements We need to have two big doubles public big double etch for achievement level one And we are going to have etch level two All right Now I'd really like to do an array here But the problem is that players with previous saves that don't have this feature will get an empty array All right, because this is defined because if we define an array here, it's only going to be defined once until we call this public player data or full reset Now that's an issue and I don't know how to solve that yet. So we're just going to do this for now There is something out there that can fix that but For now the only solution I know is that it's going to relate to version control Where you basically take that old save and you apply the new stuff and if it doesn't if that if it doesn't exist All right, so make sure in our full reset our etch level One and two is equal to zero. We are done with our data. Now, let's head down here So Under here, we're gonna we're gonna create episode 16 For me. I'm doing that at least to organize All right So next we need to create a game object so we can find our Stuff which this is our game object the achievement screen We're basically going to search through this achievement this game object and look for these two right here We're going to look for our script achievement in each of these game objects All right, so we do this by adding a game object We can call this achievement screen And we're going to add a list. This is we're going to manage all of our um, achievements so public list type achievement Is equal to now we need to name it achievement list Is equal to new list type achievement parentheses semicolon and I said pulik it's public All right, we're good there Yep, all right So next in the public start we need to start searching for the stuff inside the achievement screen so we can create a four each And we're going to just put var because we are already defining what this object is in the following statements So for every object Inside the achievement screen We're going to get the component Get components in children Make sure it's get components not get components because get component is a single object Get components is a list of objects, which is what we're handling right now And four each cannot do get components. It's get components. Okay, so make sure you're paying close attention to that I completely screw that up last Last time I tried this which is why I had to remake this video because it took too much time And we're going to do type achievements. So the reason why we don't need this here. It's because we're we're searching For achievements and we're going to sign it to this var. So if we put achievement object I mean, we already know what it is. So it's kind of redundant All right, so then every time we run through this we're going to add to our list And what are we going to add? We're going to add object Or obj you can name this whatever you want. Whatever makes sense by just put obj for short You can even put x if you wanted to Just like that that works too What's wrong Can't resolve symbol x Okay Oh, right We need that parentheses. Okay, that's it That is it for this start method All right So we're going to make a new method. So before we start that I'm just going to type up here run achievements So we're going to make it that method in a second. So copy that All right, and under the update method. I'm going to close that. Oh shoot. I still have this stuff All right, we're going to create a new method called public void run achievements. So I can just paste that loop So we have public void run achievements all right in here we are going to Manually up not manually automatically update each achievement So this is also where I ran into an issue last episode Is that I try to make it into a for loop to make it as sweet as simple as possible, but I couldn't there's some It was this stupid Level thing that I couldn't figure out Because I try to loop through I try to making a new array and assigning it to these two And trying to loop through that but I figured that it was just changing the array not the actual variable So that clear that didn't work. So I'm going to figure out something else for that But for now we're just going to make it look Look reasonable. All right. So before we start doing anything in here and we can also make this private We need to create two objects up here. So the first one is going to be a private static string array We're going to call this the achievement Strings this is for the names so you can do achievement names if you like It's going to be a new string array And we're going to assign our achievement names in here I hate how it does that. All right. So the first one the first achievement We're going to do current coins. So whatever your coins currently is so we're going to do current coins And our second one is going to be total coins collected all right And we should be good with that Remove that equal sign. Yep. We're good for that. And our second one is going to be a private big double array And this is going to be our achievement numbers Because the reason why this will work is because we don't need to change them unlike levels. We actually have to change them So I did this exact same thing with levels, but it just didn't work So new big double array and we are going to Do data coins for the first one because that's our current That's our current coins And now the second one we need to create a new variable which I've already created up here Which is called coins collected. So make sure you create coins collected It's a big double and you make sure it's set to equal Make sure it's set to zero in the full reset just like that And down here, you're going to type data dot coins collected And that's it So now we need to make this even easier We need to actually do the achievement stuff. So this is going to manage each Each achievement So now we need to create one more method. All right This will be called a private void update achievements because we need to make sure it levels up once it's done So we're going to set up a few things in here or we're going to input lots of things in here So the first one's going to be string name So it has a name so the big double First big double is going to be the actual number. So we just put number in here And we're going to ref big double level because we're going to be changing the level inside here So we need to make sure that changes outside of this method Um, we're going to have another ref because we're changing the the progress bar. So the fill is the progress bar And we're also going to have the title text in here. So we're going to be changing that so we have to have the ref And another ref text, which is going to be the progress text. All right, so this should be good to go All right, so first of all, we need to create our capacity which we're going to run it on an equation called cap Which is equal to big double dot pow 10 level so that's basically 10 to the power of level So now make sure I highly suggest you to use this equation unless you want to Figure out how to do the math for the for a future equation. Okay, so make sure you have this exactly Because I really don't want to make a new equation for every single person Unless you know math. Okay, so I'd I'd recommend you use this equation. It's pretty it's a pretty, you know Easy one to do All right, so We're going to change our title text before we do all this nonsense for leveling up So title it's just title title text is going equal to So we have our name so we're going to put name and what we did here Is that we have our achievement name and we create a new line and we have our level right? Okay So we have our name We're going to create new line by doing backslash n We're going to have parentheses in here and and we're going to put curly braces And put level inside. We have our achievement name All right, so for progress text It's going to be equal to dollar sign And uh So here we need to have our first number Because it's a number over capacity so number Slash cap And that will be this number right here What we need to add our notation. So basically what we do is do Notation method Put it around there and then put f2 for two decimals Same thing here I don't know why that did that. That was a glitch Usually it's supposed to wrap around it, but f2 just like that. So notation method the variable and f2 That's what our progress bar text looks like And now we need to control one more thing, which is our progress bar. So we just type our big double fill method that we make in our that we made in our progress bar episode In here we type number for the first one cap and then fill All right We're doing number divided by cap, which is this which is why we do number cap fill. So it's x divided by y All right, time to do the level up stuff. So hopefully this will all make sense So we're going to create inverted in statements. So basically if it's false, it's just going to return So we do that by doing if number Is less than cap and we're just going to return and we're just going to ignore the rest of the code and return it. Okay However, if it's true if it's greater if we can level it up We're going to create a temporary variable called big double levels equals zero We're going to check one more time If one over capacity is greater than zero greater than one greater than or equal to one where we can add on another level We're going to we're going to assign levels to this equation floor lock 10 One over cap plus one So basically It will use this equation to predict how many levels you can get So let's say you currently have one coins and it's level zero and you get a million coins You can level up around and see that's one. So that's 10 100 1,000 10,000 100,000 you can level up six times that will do this for you So that's why I say that you got to use this equation first unless you know how to do the math to change this right here Because if you make this Five to the level this is going to be completely different. It's just not going to work. All right Oh and one. Sorry. It's supposed to be number I did this yesterday. So I did one I changed it now All right, and in here at the end we are going to add level to levels And we should be good to go So now we've got to finish the run achievements So we just got to sign all of this stuff that we currently have So for string we already have our names up here. So we're going to do achievement strings zero for our first one Our number is going to be Oh, this is going to be achievement numbers by the ways Achievement numbers for the big double ray For here, we're going to do achievement numbers index zero And here we're going to have a ref. This is going to be our ref data dot atch level one So this is where I try to make the array here Is because I actually changed this variable in here So I tried to make it an array thinking that would change But it doesn't because it's just an array of numbers set to this So it doesn't work. I thought it would I mean it's kind of clever, but it doesn't So we have our data dot each level one And now we need to have another ref for our title text Which is going to be achievement lists Index zero dot title. So that's why we make that list because it makes it so much easier All right And in here we need to make one more which is achievement lists Nope achievement lists Zero dot Progress and that is it We have an extra argument. What's wrong? We're forgetting our fill. That's why all right, so ref Achievement lists put it after the level Zero at index zero dot fill and that should be good to go Oh comma All right, we have our thing right here now. We're just going to do it for the second achievements. Would you press enter? achievement strings one Numbers one achievement list one achievement list one one And then you change this level to two That's it. We have our achievement successfully done And this should work for the first time and I think I did 10 times faster than I did yesterday I spent like two hours It's not good. It was just some really dumb errors Um, so yeah, it should be good here. I don't know what this is Uh Yeah, that's just yeah useless. All right. Anyways, we can go back to our game Oh one more thing we need to create a button for this or a method for the achievements button So we just go all the way down here change tabs So we're going to add another one called achievements And we need to have an achievements group So we go all the way up here We're going to add achievements groups to episode 11 achievement group all right Copy that go all the way back down here And let's create another one of these all right And we can set this to false and set achievements to true And we can just copy these And copy achievement groups like so just like this and now it should work All right, we can get out of here So now the nice thing about this prefab is that we don't have to keep dragging this title progress click bar Every time we copy and paste this achievement So we can have 100 and not even have to touch this ever again unless we add more stuff All right So we have two achievements You don't have to do anything here for game manager We need to drag our achievements group, which is going to be our achievement screen We need to add a canvas group first canvas group And we can drag that in here And we need our achievement screen for the game object here too Save All right And for our upgrades button We need to rename no our achievements button. We need to rename this to achievements as well So we can actually access it And now let's turn this to zero and it should work Save it and play All right, so let's test it. We have our achievements right here. See this is currently right here So if we get more money This will increase the achievements and right now it's at level three. So that method clearly works Because it started at 10, which is level zero 100 no it starts out. Yeah, it's level zero No, it starts at one one 10 100 and now we're at a thousand so that's three levels. All right So now if we spend this should go down, but they should stay So let's do it Let's buy some here. See how this went down. This is our current coins And now that's the coins collected. Anyways guys, I really hope you enjoyed this video Thank you so much for being patient with my very slow uploads all these new subscribers coming in and looking at my analytics It's just looking awesome. It's motivating me like crazy. I promise I'm going to upload as many videos as possible And continue building on to this series. So if you join this video smack like on this video Subscribe to my channel and turn on the bell notification share this video with your friends If you have any questions join my discord or comment down below More members on my discord. I highly appreciate it. Anyways, have a great day. Peace One more thing I want before I want to end this video I just want to scroll through my script real quick just to make sure you guys are up today And hopefully mine looks close to yours. Mine might look a little different from what my actual series actually followed Just because I had some issues in the past. So anyways, here's what my script looks like I'll just scroll through it. You can pause whenever And I really don't want to like restart I don't want to do the whole series from scratch because I know that will take me a while too Even though I can easily just make it But yeah Hopefully mine looks similar to yours If I'm missing a few methods, then don't worry about it means you're probably better shaped than me All right. Anyway, thank you guys