 Hello guys, welcome back to the idle game tutorial series for Unity C-Sharp. I will be continuing from the first part, the second part of the series. This time I'm going to be doing upgrades and production. So start off with what's set up our user interface for a second. We have the coins text right here. I'm going to copy and paste it, control C and control V. So we have our click button right here. Probably not the best spot for mobile game, but who cares for now. So we have our click button. I'm going to make two more buttons. I'm going to control C, control V, control V. So we're going to make this one a click upgrade. And now this is going to be a production upgrade one. So this one will produce coins per second. We have our text here, which we're going to call this a click upgrade. It's not a good name, but we got click upgrade one. The cost is going to be, let's say, 10 gold or 10 coins. And the power will be let's say plus one click. Okay. And then the production one will be the exact same. All right. So we have our layout done, ready to go. Now let's jump into the code. So we have our method that we discussed from last episode. So episode two. So what did we create? We created two buttons, one, two, three texts. So we don't need to create a button objects just like before, but we will need to make two more of these click upgrade or these click methods because each button in order to use them, you need a method. All right. So we need to create two more of these. And we need to create three more of these texts. All right. So we have production upgrade one text and click upgrade one text. So we actually need some values too, because we have our power, which we technically don't need. We just need the cost for each. And we can add levels if we wanted to. So I guess we can just do level one, if you want to. It's not required, but you can if you want to, but I'm going to anyways. So we're going to start with the click or the coins per second. So we're going to need another double because that's what we should always use. We're going to do coins per second. And our next one will be another double. We're going to do click upgrade one cost and then another level. Actually, this is going to be an integer or an int because it's going to be the upgrade, but click upgrade one level. You only need ints for the for levels. Since they can only go so big, you know, I doubt you'll have trillions of levels. Anyways, unless you wanted to, then that's when you move up to double. So our next one will be this. So we're actually going to copy paste that click upgrade cost. We're going to do production upgrade cost. And then we're going to do the production upgrade one level. All right, we have all of our variables in our text ready to go. Now we got to start we got to start with variables. So since our cost for this one, the click upgrade will be 10 and production will be 25. We're going to take this one set as 10. Click upgrade. And then we're going to take that production and set as 25. And the levels, they're automatically default is zero. So we can delete this. If you want to have it there, just in case anything changes before it, then go ahead. So now we need to update our text because actually, for the production costs, since it's just level, we can leave it aside. But if it produces two per seconds, then you might need another like power variable to tell you how much you're getting per second, which we'll we'll get there eventually. And I'm pretty sure that should make sense, at least. So we're going to display all three of these texts. Actually, I might do that. So first, the coin per second, text would be since this is the only thing that's producing anything, actually, do you know what, we need to update the coins per second first. So what is that? What is that factor so far? Love basically, your power is your level. So we're going to take the production upgrade one level, and just set it as that. If we had another upgrade, so if we have like two, and they both produced one per second per upgrade or per level, then we'll just add them together. But if this one was 10 per second, then we'll just multiply the level by 10. Unless there's like some other upgrades, then you just multiply it or even more or add on to it. But we're not going to do that since we only need one upgrade for now. Let's see. Now, we need to display the text per second, which is going to be coins, because that's our number right here, plus space, because there's a space between the zero and the coins, coins slash s, and that'll be coins per second. Oh, yeah, don't forget to talk text attribute. Yep. Just don't forget about that or else it will not work. Because if you don't do that, it will think that you're trying to set this as a string. A string is like a text, but you don't like display it. It's like a string of like random letters. This is a string right here, but we're applying it to a text object so we can see it on the canvas. If you did a string, so like let's do string temp equals blah. Now, if we want to change the string, we can just do hi. We don't need to do the top text because a string is not a text, if that makes sense. All right, next one. So click upgrade, or so this one's going to be a little bit because we're spacing things out. So I'll let you guys copy that. All right, so now we're going to start with the title. Just click upgrade one. And to enter or make a new line, you do backslash n. There you go. That would just automatically create a new line. If you space this, they will add another space right here before you enter. So make sure it's right next to it. And then cost, space. And then we're going to do the cost of the click upgrade one, just here. And we're going to do another plus. We're going to type coins, space coins. And now we're ready for the next line, just right here. And we don't need to change this. So we're just going to do power plus one click. If there is a prestige system and the click value change, then you would just create a public double. Can't type today, click upgrade one power. And then you would just do plus one. And that string. And then do that. And then this number would change to whatever value you want to, but we're not doing that yet. So we're just going to leave it as plus one click. We're starting things basic because I feel like that's what a lot of tutorials do wrong is that they're too, they're a little slow and they don't really explain what everything does. I had to learn myself rather than the idle game tutorials because they're not that good. That's what I'm here for. All right. So anyways, level, space, we're going to add the click upgrade one level. There you go. So now don't I forgot this twice in a row, but don't forget to talk text right here. It's very important if you want to be able to change the text and it will underline red if you forgot anyways. So this right here should display this right here. So we're going to copy and paste it since it's the exact same thing over here. And we're going to change the text by copy and paste in production upgrade one. And we're going to do production upgrade there. Power. It's just coins per second. So we're going to do some coins. We're going to do coins per slash s. And it should be good to go. Oh, yeah, don't forget to change the variables to that's very important or else we'll be getting the same results. There you go. So now everything worked but the buttons aren't doing anything yet. Why? Because we haven't made our button methods yet. So we're going to make two more public void by click upgrade one. And a lot of these tutorials make these things so like different scripts for each of these buttons. It's not that's not required. It's so simple to make an idle game that and the tutorials just really they struggle to make it seem easy. I mean, it's if you look at it, it's not that hard. It just takes time. So click upgrade. So we're going to take the level. What what's changing on the buy upgrade? Well, the level is going up by one. This is a good this is a good start to use the plus plus because you only do it once. But if we're making a buy max, then we would probably use that. But we're using the plus plus because it's a good situation to use it in. It's easy. It's clean. So the cost is going to change. Usually most idle games do 1.07 through 1.15. So yeah. So we're going to do 0.07 just to be simple. You can do whatever you want. But that's just using the default 1.07 through 1.15. So we're going to do 1.07. The cost will change by this. And your click will go up by one. So we need a variable because this is changing my one. So we're going to go to episode one, we're going to create another double public double, we're going to do coins, click value. All right. So we're going to start off with as one because if it was zero, it wouldn't be doing anything. And we're going to change this plus equals one right here to coins, click value. All right, back to the top or back to update. Actually, we don't need to update it. So what's happening to this, it's increasing by one every time you buy. So the cost actually has to subtract from this. So we're going to get our coins. And before it multiplies the cost, we want to do coins minus equals, which coins equals my or minus equals is basically coins equals coins minus whatever. So this is shorter coins minus equals click upgrade costs, which means if you had 100 coins and the cost was 10, it basically takes away from the coins. But what if we had zero coins? How do we know if we have enough? It's easy. We just creative statements. So we're going to call it if coins is greater than or equal to click upgrade one cost, we will execute this piece of code. So we'll do brackets there or braces, curly braces. There you go. If you did not have this, it would just buy whatever you go into negatives. That's how you know if you don't have enough. We'll get into buy maxes later as well. But we just want to stay basic. We're going to copy this right here and do the exact same for the production upgrade. We're just going to replace all the names, production cost, production level, and the production we don't need. We don't need this right here. The cost is going to go up by the same amount. So we're going to copy that copy that. This is good to go. All right. This is our time to test. One thing we're actually missing is the update. And we need to update the coins. So coins plus equals coins per second. This is not a valid statement right here because this is updating for me 144 times per second because I have a 144 Hertz monitor. So you're basically, if this is one, you're getting 144 coins per second. So how do you fix that? You multiply whatever you're wanting to add to it by time dot delta time. This basically calculates the time between each single frame and multiplies it by coins per second. So you're guaranteed to get one coin per second rather than 144. So basically, this is coins divided by 144 if it was a constant 144 FPS. So it calculates that for you. So it's really easy and simple to do. And it's very important. And I feel like that's what a lot of tutorials actually get wrong. They do some other like divide by 60 because you don't know if your FPS will drop to 50 because you have low battery mode or something like that. All right. So we're going to go back to game manager. We're going to drag all of our taxes to here. So the coin per second right here, click upgrade and production upgrade. All right. So now we need to make these buttons do something. So just let the click button. We need a, since I copied and pasted it, this is already set up for you, but we need to click on the idle game, idle tutorial game dot click, go to it tutorial game. And we need to change to buy click upgrade. And it's the same thing for production upgrade. There you go. All right. So we're going to give this a try. The text might look whack at first since you're just just raw code, but we'll see what it looks like. Perfect. We got a perfect. So now we can click. We're going to buy an upgrade. There you go. Now you're getting two per click and see the cost is going up. Okay. So this is a mess now. I'm going to go over that. So now we got our production upgrade. Now we're getting one per second, but we need to fix this right here. This is called floating point or something like that. We need to round it. So we're going to stop that. Okay. So the problem with this right here is that we need to round up the coins per second to no decimal. We can do two decimals if we wanted to, but that's a really good once you get into the exponents, which I will do rounding systems later on. So we're going to, we're going to do this for every single text, but we're going to add this following attributes dots, two string parentheses. And then we're going to do F zero. So zero is the amount of digits. If we want to do 16, you want to have 16 digits, go ahead and do F 16. But F zero makes us have no decimals whatsoever. Never unless it changes, unless you want it to, you can change it anytime you want it to, but just for this text, it'll make sure you have no decimals. So we're going to copy and paste this and make sure it's the same for every single one of these variables except for level because levels and integer are an int and it will never have a decimal. It'll always be a whole or a whole number. All right, save that. And then we run once it's done loading. Boom. Alrighty. We're going to add by one. So now this automatically rounds up to 11. The problem with this is that if you have a, if you have, um, let's say 11 coins, but it says 12, that number could be 11.6. So clearly you don't have enough. So we're just going to keep buying. See, I had 12, but it wouldn't let me buy because see at 14. Okay, let me buy that time. I'm trying to find a good example. Yeah, it's probably too late now, but now you can just buy a bunch of these upgrades. And now it goes up two times per second. So now we got 10 per second, 12 per second, so on. So that's the basics of upgrades right there. Um, it's modular. You can change these values, whatever you want, you can change the cost, whatever you want, you can make this a thousand if you wanted to, you can give the click power, um, whatever you want. So, um, for episode three, I'm going to do another row of upgrades, but with powers and stuff like that. And I'll do by maxes. All right. So thank you for watching. I hope you enjoyed this tutorial. I'll see you in the third part of the tutorial. Peace.