 Hello guys! Welcome back to another auto game tutorial video. Oh wow, it's been a really long time since I've uploaded it. I am terribly sorry for this delay. Some corruption stuff has been going on. I lost some pre-recorded videos and kind of lost a little bit of motivation but I promised myself that I would never give up and I've been really busy too with hockey, job, with work, real life stuff and working on my own game as well. So I've been really busy and kind of decided to just not worry about it for now since the other videos are doing good. But I feel like that I need to stay up to date with my videos, with my recap that I provided. So today we're going to be doing as I promised my episode 10 if it'll load. We'll be doing canvas group tabs, menus, etc. So the purpose of this is to make the main screen cleaner and to separate stuff. This is really important for when you're adding if you want to have a different page of a sub game I guess with different currencies and stuff and you don't want it running in the background then this will be the way to go. So before I get started, if you want to use less RAM or less of your phone power or whatever you're using to run the game, my suggestion is to use something called. So you have your object, so we'll just make an image real quick called example image and we'll use a class called game object and then we'll use a method called set active that we're this is not working because we're we'll do it here. So game object dot set active, which is the method and we put a Boolean inside. If you if it was true, it would enable the object right here. So you just turn it on or off. This is true right now. If we set it false, it'll run just like this. Nothing in this will work. If you turned off this right here, then the script won't work. Because this whole object is just not there. The script is not there. If you turn it on, it's working. See, we can disable the script to do the same thing. But that's not what we're doing. If you don't want to do that, if you don't want to disable your scripts that you have inside the game object, there's an alternative solution, which I'm going to show you. This is basically the easy solution. This one's a little more complex solution. So I'm going to make an empty object. We're going to call this the main screen. And we're going to separate them into two. We're going to have a main screen. And we're going to have an upgrade screen. All right. So all of our main screen stuff will go in here. All this upgrades will go in upgrades. So I'm going to make sure I have all my upgrades right here. I toggle them off. Oh, yep, there's all my upgrades. I'm going to drag them to the upgrade screen. And there I go. And for now, we'll leave the prestige on the main screen. So we'll get everything else except for the currencies. So the click button and the prestige button will go on the main screen. This right here is basically the header. So why not? Let's just make a header object. So we'll make create empty. We'll call this header. And we'll put everything inside this. There you go. So now if you turn on and off, that's our header. You can add an image if you really wanted to to make this stand out from everything else. Oh, yeah, another thing before you drag this in, make sure you position your thing to where you want your stuff to be. And you can change the color, drag all the stuff in here. And I'm going to anchor this to the top of the screen. So whenever you change resolutions, it will follow. It won't move down. And I'm going to change all the colors of the text to the background. So we get good contrast. There you go. So now we have three objects. We have a header main screen and an upgrade screen. For the main screen, we're going to add something called a campus group. And we're going to do the same for the upgrade screen. So by default, we have the alpha set to one, the interactable set to true and block recast sets to true ignore parent groups. I've never used it before. I don't exactly know what the purpose is. But I'm guessing is that if you toggle this, if you turn this off, then maybe or if you have a canvas group in a parent object, it will ignore this or something like that. I'm not exactly sure what that is. That's my best guess. It's basically to oppose another canvas group. That's my best guess. If you want to play around, go ahead. So how this works is that if we set the alpha for the main screen to zero, we won't see the main screen stuff anymore. We can set it to 0.5 to see half transparency, 0.1 to see a 10th transparency. And it's zero to one. So we're going to set that to one. And I want to set my upgrades to zero. So we're not done here. We have these two other settings that are enabled. Right now, we're still able to click this invisible button that we can't see, because the interactable is toggled. So we want to make sure that's false and blocks recast. We want to make sure that's false too. Because if this was, if this was invisible, and blocks recasts wasn't toggled off, or if it was on, but these two were off, then basically we can still click through this object right here. We can't click through it. So if we turn this off, we are granted the ability to click anything under the main screen, because this whole thing is an object. And if this thing was enabled, we wouldn't be able to do the click button. So main screen is going to be all on, except ignore parent groups. We're not going to talk about that at all. And everything will be off here. So in the code, we will do this. We're going to go to the top. I had to borrow someone else's code because I lost all of mine, and I was able to transfer it. Well, that meant a lot. I really appreciate it. So we're going to call this one episode 11. We're going to make two canvas groups. We're going to do a main menu group and a public canvas group called upgrades group. I always name my canvas groups, something and then group, because it's easy to know what it is. I know it's a canvas group. So by start, we always want the main screen to be loaded. So what we do here is dot alpha equals zero. And we got to do the same thing for interactable and block ray casts. But these are Booleans. So we got to send the true or false, since we want them off, we want to assume the false. And that's it. We can do the same for upgrades. And actually, these need to be true because we want to be able to see our main screen, of course. So this is a little mini lesson. I'm going to show you guys this is to reduce the repetitiveness in your code. So you'll see a lot of that here here. I'm going to show you guys how to make custom methods. So what you're going to I'm going to call this public void canvas group group changer, something like that. Just name it whatever you want, something that you'll recognize. So we're going to copy and paste this code in here. So this is something really cool. Inside these inside this right here, we're going to make it accept a Boolean. We're going to call this I don't know you can call it whatever you want, I'm just going to call it x. And then we're going to also have a canvas group called y, for example. So we're going to replace the main menu groups with y. And we're going to make it if statements. So if x, if we just leave it at x, this is true. This is false right here. So we want it if it's true. Then we want this stuff to happen. Because if it's true, we want to turn on our object right here. And so we don't we don't need an FL statement just an if statements, we can type return. Want to lie? It's because we can ignore this stuff down here. So basically, if it's true, it'll run only this part of the code, it will never ever reach this part. If it's false, it'll skip this part and it'll only run this part. So we can make this the opposite. We'll make it false. And this is really cool. So now we can change the six lines of code that we have made. And I'm sure you'll use this a lot. We can do canvas group changer, we're going to do main menu group. Actually, it's the bull. So we're going to make it true. Main menu group. That's all we got to type. And then we got to get rid of this. And now the same for upgrades group, we can make this false. See, that's so much easier. And now that's how you make a custom method. And that's how you change or toggle an object on and off. That's really cool. I love doing this kind of stuff. Using methods like this will help your code make much more sense than just having it look like this just everywhere. This can be simplified so much. But I feel like that if you use this as an example, if you put in variables in here, you can change them inside of a method instead of having to do it copy and paste every time you can just use this one line right here. Anyways, let's get on with it. So we have so now it'll work. I'm going to show you an example. So I'm going to keep the upgrade screen on just to show you that it works. I'm going to go to game manager, make sure that's on. Oh, I forgot to delete a line of code. All right. So now we have to drag our canvas groups into our script reference. So main menu goes there and upgrades goes there. So what we do now we are ready to go. So once we start, we should not be able to see the upgrades. Sweet, it works. So now we got to make sure we have buttons as well. So we're going to do a little bit of adjustment. I'm going to go to my upgrades. I'm going to slide everything down. Same with the click button. And I'm going to make two new buttons. I'm just going to copy and paste this one. And this will be a part of the header. Technically, it is not like a part of the header. But if I want to keep it together, I can add to the header. But to make more sense, since it's not part of the header, I guess I'll just keep it aside. So this will be called the upgrades button. We'll keep that over here. And we'll have a main button. So let's line stuff up. So I'm what I'm going to do is make sure everything you can do how line it up, however you want. I'm just going to put this here. So then I can copy, delete and then paste component values. So this will copy its position. I'm going to move this up here somewhere. And I'm going to do the same thing with the main button. I'm going to paste, make this x value negative. So it's on the opposite side. And these are also anchored to the top because I don't want them sliding down. So let's change the text or click main. You can call home upgrades. So these are really easy to implement. We're going to make two more methods. Called public void. We're going to make one method. Let's actually let's try to do this in one method. Let's challenge ourselves and hopefully challenge you guys to understand this concept. But this is going to be called change windows or you can call it change screens, change tabs, whatever you want. So in order to do this, we need to create a int public int tab switcher, name it whatever you want. And that will also be set to zero at the beginning. And we're going to do switch case, just what we did here, because we don't want a bunch of if statements, if else statements. So switch tab switcher. So if this was zero, which is what we start with, we can grab, where is my lines right here? These two right here, we can paste it right here and break. That basically stops the whole thing. Oh, one more thing. We need to set tab switcher zero to one. As you add more tabs, you could do zero, one, two, three, zero, one, two, three, four, stuff like that. This is just going to alternate from zero and one. So we're going to make sure the main screen goes false and upgrade screen goes true. And then case one. Oops, I don't know how to type. Same as usual. Nothing's changed, guys. This is going to be true again. And this will be false. And tab switcher will set to zero. So now we know that it alternates right here. And we did it all in one method instead of making one for go to menu, go to upgrades. It's super easy. The power of variables, switch case, if else statements, all that good stuff is very important to keep your code organized. All right. So we're ready. So we need to give these things to work. So we're going to assign main button to change tabs. And this one will also be changed tabs too. They both will. So I just noticed a problem. I just see that if we click on main, if we keep clicking main, it'll alternate from each screen. I totally forgot that it does that. Okay, so we need to actually get rid of this right here. Maybe. Okay, so this is what we're going to do. We're going to put, we're going to make a put a variable inside here. We're going to just call it x or ID. I like these ID. So we're going to have the same switch ID. But instead of it changing from zero to one, it depends on what button you assign it to, which, which is what exactly what we did in the upgrade one right here, the upgrade ID. So if it's zero, we'll still have the same thing. And we'll make actually, if you want to make this readable, we can do string ID. So we can do, we can do this one will be upgrades because this is making upgrades true. And this one will be main. That's it. So now we got to go back to her main button, look for change tabs string. And we're going to set this to main. And we're going to do the same thing for upgrades button, change tabs, upgrades. Now it should work, save our code and let's play. So upgrades main upgrades main, we got it. So now everything looks a little bit more simpler. All right, cool. Um, anyways, thank you guys for watching. I am really, really sorry for the long delay. I missed making these videos. I thought about it. I think about this channel a lot. I get notifications whenever you guys subscribe. I know like what happens. I see you guys watching. I reply, I try to reply to comments too, because I'm always longed into the account anyways. So I just think about it and I just never get to making the videos, especially after all the corruption and all that. But hopefully I'm back. I will try my best since it's winter break. And yeah, I really hope this was helpful. I hope you guys learn off of this and I accept my apology. Um, yeah, anyways, have a good rest of your day or night. And peace. Yeah, that's what my father taught me. But for now I'm going through the motions of letting go because my mind's telling me yes, but my heart really don't know your heart. When I got to know it, yet I still see a glow. So we had the hottest love. Why'd you leave me in the