 Hello guys Crypto grounds here welcome back to another unity C sharp idle game tutorial video this up there 32 and today We are going to be doing some critical click So this means two parts the first part is going to be having a little animation where the if you click and you get the critical Click it will fly across screen So I'm gonna set up the animation first the reason why I want to do this first is because if we're gonna Have a critical click which is gonna be a percent chance. I want to be able to test this This flying things of having to click a hundred times and hoping for it to happen So that's the reason why we're gonna do that and then the second part is creating the critical click Which will be based on an upgrade so let's get started with this and I am pretty excited I just discovered how to do this beforehand So I should how I should be refreshed on how to do this anyways We're gonna be focused on our click button here today. Okay, so we are going to go to our click button Remove this I was experimenting and we're gonna create Okay, so we're gonna create an object for click. Okay, so just Goed you can do this wherever you want. Honestly, you can even do this in the canvas So you just do right-click UI and create a text. So we have a text object here Let's decorate this first. See what we want this to look like Okay, so I decorated my object. It looks like this so far. It's just a text and next thing we need to add an animator Because we are going to animate this Okay, so now once we create an animator We are going to go to the animation tab and we're gonna create a brand new animation And it looks like we don't have an animation folder. So let's just create one It's been called animation and I've said that a lot in the past 30 seconds All right, let's read in that. I don't like that should be animations Okay, and we're gonna call this critical click Effect okay, keep this name. It's gonna be important in the future All right, and this should be a really easy thing to affect Okay, so all you gotta do is just click on this record button here Which is the right circle and let's grab this right here and just let's have it Locked in the center of the screen or wherever this thing is this button is and now every five Let's just gradually move it in like an explosive Motion Now you can just whatever you want you can make it go crazy or you can make it just go thin air and just disappear or something like that Okay, so mine looks like this. This looks like it's too severe. I think we should flatten that that looks a lot better I think they should fall a little more though. I don't like how it curves like that I think I should just continue to like Yeah, there we go We Like that now I want to make this fade to so we can do is change the alpha Temporarily so we want the one to be at the start and at the end we want this to be zero And now what this does is that it creates a little fading effect We now looks pretty so that's how you create an animation if you've never done that before and it's very simple Very basic you can now you can change these to make them longer You can shrink it you can move these all the way you want or anywhere you want So right now this is 250 milliseconds that's how long this is right. Yeah Yeah, no, no, no, yeah, no, this is so that right here zero 30 This is half a second and this is a second right here. So this right here This would be almost like around 400 milliseconds long. I don't know. I don't like their time signature thing. I think it's weird But yeah That's our animation. So we're gonna stop we're gonna get out of that preview mode and What we're gonna do is we can name this whatever you want. We're gonna call this critical click and We can drag this into our prefabs and Delete this Actually, no, it's not delete. That's actually no, no, no ignore that Or you do Okay, I'm gonna delete this prefab. So let's unpack this real quick unpack prefab completely Okay, now what we're gonna do we're gonna create a script in here real quick We're gonna call this critical click make sure you spell this correctly first of all This looks like it wasn't spelled correctly either Okay, so we're gonna create a new script called critical click and let it create on its own Okay, and now let's open that up and in here we are going to define some properties We can get rid of some of the stuff that we don't need. Okay. So first thing we need a game object Okay, and that is going to be our pop-up and We need an animator which is going to be our Which we can call this animation, okay, we call this whatever you want you call this Annie if you want to No Okay, and now we're gonna create a method in here to play this game object and to automatically destroy it after it's played, okay Okay, so in here, we're gonna call this Public void play now you can do whatever you want in here You can do a lot of fancy stuff in here, but all I need to do is Annie Dot play and remember our anime Animation name it's called critical click effect. Okay, so we got critical click effect And that's all you needed to put it down here for the animation and then after that we are going to destroy the game object And this would be game object comma and then so let's see our animation is Roughly about half a second long. So let's just make that point five seconds Now if your animation is like 1.2 seconds long, I would make it around 1.2 to 1.5 seconds. Okay And That's it. So now this game object will be destroyed shortly after or pretty much right after this animation is done playing Okay, we are done with our critical click class in here and Now we are going to do we're gonna create one in here. Okay, so we're gonna call this public critical click Because we just made an object and this is gonna be called our crit Okay, okay, so we're gonna jump down to our click right here because what we're gonna do here We're gonna create a method called public void generate crit text Okay, now in this method on our text right here and we will have to call this again whenever we get a crit Right one thing I forgot to add is a game object because we want to assign this We want to make this spawn on a certain game object, right? So I want this to be called crit spawn Okay, so we're kind of making a fake spawn point or we're making a we're making an actual fixed fake spawn point and this can be called our Okay, so we're gonna create a clone because we're basically cloning this prefab so we're gonna do of our clone and We're gonna set this we're gonna instantiate And let's see. What do we call this? Is it just crit? Yeah, so we put crit and then our parent object which is gonna be our spawn and we do dot to transform because in instantiwate is Hold on. I gotta actually do this first so instantiate is The original which is our critical click right here our game object and then we have transform which is our which is the Parent object where we want to spawn it or you want to create it Because let's say we want to because if we don't create this right here It's going to spawn outside of your canvas at the very top right here We don't want that we want to spawn it where we can actually see it Okay, and then once we are done with that We're gonna call clone dot play and the play is in critical click right here this method And it'll play the animation Whenever you want to but we don't want to do that Actually, yeah, we do want to do that right and then on click We just take this generate crit text and put it in here and now every time we click it should spawn this text Also, sorry if my talking sounds a little weird. I have my retainers in currently And it's late. I should be in bed Okay, so we have our crit and our crit spawn so we haven't made the spawn yet and Okay, we're having an interview with arm barts. What do I got to say? Hello? Hello You're currently in an interview right now. Tell me about yourself good interview Good Okay, well while we're playing this I will Okay, well, I guess I'll try to continue on the tutorial. I'll meet you. Why is the bot soap? Okay, you're hilarious stop Okay, well, I guess I'm arts wants me to play this during the video. Okay, so now what we're gonna do We're gonna take our prefab that we created which is right here We still need to drag it into the prefabs folder So don't forget to do that and now we can delete this critical click object and In our game manager, we will drag this critical click prefab into the box and now we need to create a spawn point so in our Where a click button is right here. We're gonna create a Another empty aim black another empty game object right here We're just gonna call this spawn now. It doesn't have to be anything. Obviously, we can just set to we can have it No sign or just be zero by zero just create a dead-end center right here And all we have to do is just drag the spawn point right here We can also have this disabled too. So it doesn't have to interfere with anything even though it really won't because it's Zero by zero Okay, now if you play it should work Okay, so let's click here and it should play No, it doesn't okay. We forgot something. I think I know what we forgot It's something with the prefab Yeah, okay, so to fix this null reference error We got to drag in our stuff in here So since the game object and our animator are in the same prefab We can just drag the prepab to both of these boxes save it and we should be good to go Yeah, let's see if it does it safe. Yeah, it does. Okay. Now it should play Game object with animator is inactive So let's see. Is it even it's not even spawning. Is this why? Oh Yeah, okay, so my bad this spawn has to be enabled and Another issue we're having is that the animation is looping So we got to go to our critical click effect and toggle off the loop time save it and Play again, and it should work Okay, there we go. So it plays our animation. We just got to make the credit effect Happen when we wanted to so now the cool thing about the cloning is that It happens You can literally spam this button as much as you want to and it'll keep creating these objects, right? Now what it's doing is that it's making a list right here See all that clones on the side of the hierarchy. It's just creating a freaking long-ass list if we keep Spamming this button if we get an auto clicker, it'll make a giant ass list because we got lots of fun or a lot of objects being created Look at that So pretty cool. This is also another way Or another cool thing you can do and just like clicker heroes when you click on the monster it has that little That little damage effect too. You can do something exactly like this too. It doesn't have to be just for a critical click So all right, we're done with part one. So let's get sorry with part two Also before I continue, I'm just gonna make this method private because we don't really need to access it anywhere else Okay, so let's hop into our upgrade screen and for once we're actually creating a new upgrade which we never do and Since we can quite we have quite a bit going on here. I should probably make a panel So what I'm gonna do is I'm going to create a I'm gonna create a I think it's a scroll rekt. Where is the scroll rekt scroll view right here? Okay, and I'm just going to scale this to Where we don't need to include our by max into here. We can just scale it up to here I think this is not right. Okay. I see why our upgrade screen is in a small box so I'm going to expand that real quick by taking everything out of it and setting the anchor to stretch and all the dimensions are set to zero and Bring everything back in and now we can be able to snap our scroll view to the sides And we don't need these scroll bars. I personally think they're not really useful because On a mobile device, especially you don't really need to hold down on a scroll bar You can just slide also to adjust our viewport. We can just turn it off scroll rekt. This is being really annoying and Just adjust that to whatever size you like and I don't really like this image So in order to have this you can just create none. Let's see Set the opacity to zero point zero zero one in Or to have this mask to work and this mask again We'll make sure you can't see any object outside of this scroll view And I can just call this a list and this will be our viewport. Yep And it's got a mask in here. I don't need it and we can get rid of this image too Cuz yeah, our content is right here already Okay, I see what's doing. Okay, so I'm gonna delete viewport and I'm going to replace this viewport right here to content Or no content is right here and the viewport is list All right. There I go. I I despise how they set this up It's very complicated and it could be simplified with just a few adjustments and now in here Our content can be whatever size that they want. So let's put our click upgrade one game object in here And now if we drag it out, we should not be able to see it outside of this canvas pretty cool So let's drag the rest in We only have these yeah, we can keep the by modes out of it. So we have our four upgrades and Now it should scroll accordingly So let's create a new I'm gonna Let's copy click upgrade one No be down here And also another way to kind of hide this mask You can also just turn this off and then you can see it or you can just drag the content outside of the list that works, too. I Personally drag the content out of it. Even though you can just click this button. It works exact same Okay, so this is gonna be called critical click Okay, and inside here we have our max our actual upgrade and the progress bar So I'm just gonna rename everything and I couldn't make I could make a prefab out of this too Because it's the same upgrade and I already have a Mars upgrade, right? Yeah, never mind. It's a little simplified Okay, so this is what it looks like. I have max which is by max button upgrade and bar So in the upgrade, this is just me called critical critical chance 100 times critical chance because that's what it's gonna be. It's gonna be 100 times your current click value and The power is going to be plus zero point. It's gonna be plus 0.1 percent Okay, and we can also add a limit to this upgrade so it doesn't go beyond 100% and Yeah, that's all we need here The nice thing about what we did in our upgrade manager if you've been following the tutorial series along is that we can add On to this array right here. So I have click upgrade text. Let's see Now what would this be considered? This okay, so we have click upgrade production This can be its own thing because I only I'm only gonna have one of these, right? So I'm not gonna add on to this click upgrade text. I'm just gonna create a new separate text and Yeah and I should have made this by max. I should have made a single array for that But I really didn't think about that because this is exact same by max so let's just create a Critical chance and I'll also create a by max chance for this too. Do I already have a tech? Okay, I was like, why is it like that and I do have a progress bar. So I should make an array for this Okay, I can I can do that. So let's just replace these I'm just gonna call this upgrade bar and then upgrade bar smooth and This is gonna be a size 2 image array and you can expand this inside unity If you want to create more If you want to do this for all of your upgrades now, that's up to you Just change this to whatever size and in unity you're gonna have to adjust that size because changing this number here Isn't gonna do anything here. So make sure you change it here and in unity and in the expector He's big dumb and doesn't do that automatically except for on compile and Okay, so now we just got to add indexes to our progress bars here just like that since it's now an array and our cool So now we got to do the same thing for our Our costs, okay, so what's our cost gonna be? We have quite a bit of stuff here This is starting to look kind of a mess. I kind of wish I just had all this thing add all this stuff into One singular Array That's okay So now this doesn't mean you know, hey Now I really don't feel like redoing the entire system. That's why I'm Copying pasting this if you understand how arrays work Then I highly suggest you just to do one array for costs for all the costs powers base costs all that stuff and You may not need an array for all upgrades obviously like the crit chance. We don't need one for Power, I mean It's consistent entire time unless you have different types of critical chance upgrades that again That's just how you however you want to do it. So this can be called a crit cost I don't think we need a power Yeah Because we only have one upgrade we have a crit base costs, which we don't need that as well We don't need cost mult as well We don't need unlock costs. What even is that? Don't need that Click upgrade levels. We need that we need crit levels and Honestly, we can bring these to our player data class So let's see where's our upgrades right here. Yeah, we can bring these here and Our costs actually just only our critical levels needs to be in here So let's bring this cost back here and We're gonna set it equal to I want this to be 1e3 times big double pow I want this to scale Moderately, so maybe make it two times. It's data dot level Data, where's data? Oh, this is oh, this is upgrade manager. So it's game dot data dot Crit levels cool. So now it will double every upgrade Starting at 1e3 I don't think we need to do anything else in here except we need to Let's go to our upgrades we need to set this to zero. Okay. All right Now again, I hate to make another method But I really don't like doing this I kind of wish I just did this merges all in one Okay Now if you're watching this video, I'd again, I'd highly advise you to merge this all into one method Not create numerous ones like I am Because what I can do is just create like add these to an object right here, right? And yeah, you can just like switch cases or something like that like if it's yeah Okay, we're just gonna do a buy crit Okay Let's just do var data equals game.data to make their life a little easier and it's the exact same thing right here And we don't need any index here Cuz we don't have an array So we have our crit costs and our levels will be data dot crit levels plus plus And data coins minus equals crit costs. Okay, and that is that is pretty much it. Oh We do actually need some stuff Actually doing no we only we don't need that. Okay Okay, so now we have our buy crit. We need our buy max crit Okay, now I would while loop this but that's pretty cheap. So What we can do is calculate by count and just do exactly this right here Copy this We can actually what we can do is Use our methods by max Let's do that. We already have it. Why you have to make something else? Okay, so now in here We are just going to call Methods dot by max now. How do we actually use this? Let's see. Let's find this Okay. Yeah, we use it like this so let's copy this and We can just replace whatever you want here and We will replace our fields our parameters So this is our base cost our base cost is one eight three our cost molt is two and our levels are Game dot data dot now we can simplify this to var data equals gain dot data. So we can do data coins and Data dot crit levels instead now ill by max and we need to add our non array manager at the end for our saves and Actually, we can we can get rid of this because we don't have any arrays in here. So Okay, let's invert this array to make it a little cleaner and We have our by max. So cool. We're starting to adapt to our new system. I think that's good. So creating a brand-new method every time I definitely think that's the way to go We can obviously do the same thing for these but if you want to replace them here you go use this right here and Okay We need to have our okay, so we haven't had our Cost done yet. So let's see. What do we do this? Okay We're gonna set this equal to whatever our UI is here. Okay, so I'm gonna kind of copy or copy everything down real quick Okay, I copied everything down. So it's critical chance text dot text is equal to dollar sign 100 x critical chance new line cost colon Let's base that and we use methods dot notation method And we have our critical cost and f2 for our two decimals Coins new line power plus 0.1 percent new line levels and our crit levels cool. So we got that done. We need our by max Okay, so let's calculate that now what we can do here is We have our calculate by Right, so let's just copy this format right here and Let's see. Where is it right here? Okay, we're gonna do dollar sign by max parentheses and we're gonna put our curly braces in here and We now need to replace these variables so our cost great cost our base is 1e3 our multiplier is What is our mold it is just two and Our levels is data dot crit levels Cool, that is our by max text. That is it pretty easy Now we need to actually make this critical chance work. Okay, so what we're gonna do inside the click is We're gonna create a random number. Okay, also we can cap this at so what we're gonna do is Okay What we're gonna do is add an if statement if data dot crit levels is Greater than or equal to 100 or we can just say yeah greater than equal to a hundred because actually know it's a thousand Then we're gonna return it. We don't want to do anything here same thing in our by max, okay If it's anything greater or equal then we can just fix that and Now in our by max we kind of have to control how this works Okay, and also our sadly our by mode dude does not Count in here yet. So actually what I'm gonna do is take this here This actually might be an issue. I could see why I had I struggled with this Okay, I'm just going to Yeah, I think that's fine Okay, so I see the reason why I did this it's because this is static and our By max counts is not static and that's an issue Okay, well, I'm just going to Now I'm just going to Create this calculate by max two and just return This right here. Okay now It's because this has that doesn't implement this system yet the OCD by so I'm just going to replace this with calculate by count two and that should solve our problem and In here the reason why this is a little kind of annoying to do right now Is because this by max is global for everything, right? But we want to set a limit to this So I would have to create like a separate Okay, I know what we can do we're going to create another by max here and We're going to call this by max the limit. So we're gonna have an inch limit right here Okay So let's say if N plus K is Greater than limit Then we're going to okay. So how let's open up a note document to do this math So let's say our level right now is 900. Okay, and We can buy 200 more and we want to say our limit is a thousand right Our total levels after that is going to be 1100 and that's an issue. So what we're going to do is Subtract and we're going to do a thing called math on mat min So what we can do is find the minimum between these two and obviously we want to use our min as our Example Actually, no, no, no all we need to do is Okay, I did I kind of made this mistake in my last video is Not doing the math We're doing less math this time. It's more math than usual Norther than I'm supposed to I just need to subtract these two together in order to get 100 because I only need to buy 100 Okay, so then I set N to 100. Okay, so now all I gotta do is set N equal to N N plus K. Oh, no, that's why it's N minus K. So this will simplify to N Minus equals K. All right, so now we have our by max limit So we don't have to worry about it going outside of the limit And now we got to replace this method with by max limit and add our upgrade limit to 1000 and there we go That should work like a beauty and now What is this? Interesting Okay, our critical chance So we need to create a random number in order to do this every time. So let's find our click Okay So much it's taking way too long. I still need to edit this damn piece of shit Okay, so now what we're gonna do here is we're going to create a We're gonna create a random number generator, so we're gonna do a var Crit, okay, so let's only do this if the The level for critical chance is greater than zero. Otherwise, we're kind of just doing some pointless calculations Okay, so our crit is going to be equal to new system dot random Now it has to be system dot random because you need the engine also has that as well So even though you have system implemented you can't just do random because it's going to quit and Big u.s. Reference Okay, it's gonna be confused between unity engine and system. So make sure you do system dot and it's pretty easy unlike Java Java's random is awful. I hate Java with a passion when it comes to that Overcomplicates it and now all I gotta do is just pick some random numbers Okay, so I think we should just do okay, so there these are integers So we got to pick either between one and a hundred and now how we're gonna reduce this chance So since okay So since this is an integer, I want this to be a float So how we're gonna make this into a float is that it's going to create a number between one and 100 so Okay So let's do one to one thousand and What we're gonna do here is subtract it by our Data dot crit levels and we're gonna divide this by 10 now the reason why we're doing this is because it's Hold on Yeah, I think this works Then we don't need to divide anything here. We just needed it subtracted by critical levels Okay, because once is a thousand it's gonna create a random number between one and one so that's a hundred percent chance, right? So we're creating a random number between one to one thousand minus the level In every level subtracted by one, which is your point zero or just Is it are we doing zero point zero zero? I think we are If it is and it's ten thousand levels if it's not where is our upgrades right here? Yeah, zero point one percent. Okay, cool. So we only need to do this one thousand. Okay, cool. So now what we're gonna do is So this may seem really Difficult to occur, but we're gonna check for this. So crit this can actually be a bar. So We're gonna check if crit is greater No, okay, I think I'm just confusing myself. Okay, we're gonna get rid of this minus So it's gonna create this one two one thousand automatically. Okay, so if crit is greater or equal then Yeah So let's say if it's five hundred and our chance is five hundred, okay We're gonna do if crit is greater or equal then 1,000 minus crit. Okay, so let's say this is level one. So it's nine nine nine If it lands on one thousand then yes, it's considered a critical hit Okay, if it's landed at a thousand so we actually might need increases to 999, okay Yeah, but actually We're gonna make this greater than okay Because if this is a this is a one, so it's nine nine nine we don't want to land on nine at nine and Because I'll give us a zero point two percent chance of zero point one at start for our first level Okay, so if crit is greater than one thousand minus crit that should work Okay If that's true, we're going to generate this Crit chance and we are going to also add Our total click value times one hundred, okay, and we're gonna just make things look a little cleaner What is wrong with this? Oh Okay Crit num sure we'll just re Rename this okay. Oh This would also be data dot crit levels my apologies and We'll just change that too Okay, let's save it and we should be good to go. Okay. We got to go to our game manager first Let's see. Do we have anything here? Actually, no, we don't it's our upgrade manager upgrades manager and In here we have our new progress bars. So don't forget we got to replace our original one Well, I I do at least so this is our Our bar right I have this and our smooth This is the bar right here, okay? Okay, here's our new text right here So this would be our by max text will be the second one and our upgrade text will be that one And now we need to sign our buttons here. So if you upgrade manager by Just by crit and this one will be by crit max We should be good to go. Oh One thing I forgot to do is to toggle off this This mask, okay So let's save it So we should not be seeing this pop up every time Cool, so we can buy some of this. Okay. So also now we forgot to do another thing is that we can just We can just drag this wherever you want We want to turn this to vertical only by toggling off the horizontal So now we can only scroll up and down and we can see our upgrade cool. So let's buy some of this Let's give us some money So this is a level 10 we have a 1% chance of this actually happening. So should we try it? Oh, we got it So right now we're only getting one per click. So let's upgrade this Our upgrade our by max seems awfully off now. I don't know why Okay, well, that's fine. I can just do this Let's get this critical chance So this should be giving us so 121 it should be giving us about 1 e5 oh No 1 e4 did they even give it to us? So this is pretty rare. So let's give us a lot of money. How about that? I can buy max this Okay, so now our level is 156 that's a 15.6% chance of it happening. There you go. That's a lot more. So let's set this to zero Let's watch this happen So it's not giving us So it's not giving us any more. Why is this? So it's playing this right here, but it's oh, I see because we're adding it to the coins collected Okay, I see now. So let's just add this here Multiply by 100 and we should be getting our critical click All right If you enjoy this video, make sure you leave a like subscribe to my channel if you're new and turn on this Notifications comment your suggestions down below and check out my videos in the top right corner Thank you for watching and have a good one. Peace