Transcripts
1. Why You Should Watch This Course: So you've learned how to add a rigid body as a component to a game object, you may have even checked what a rigid body is on Unity's documentation. And now you know all the properties and methods. That's cute. But can you add a rigid body to a game object, starts moving it around, add animations to make sprites walk in a world that we built using a tile set. Allow it to interact with the world and move from one scene to the next. Oh, and also have a script that is 600 plus lines of code to handle our battle system with six other battle scripts all working together systems such as the items. My name is Michael Moore, founder of WM game dev, and my goal is to make you the best game developer in the most fun way possible and developed a strategy that has helped thousands of aspiring game developers achieved their goals of creating the real-world games. And I want to do the same for you. What I've learned is that it can be very difficult to know where to start and what steps to take to go from beginner to intermediate to professional. Not only in game development, but in programming and learning how to code. And this is where the strategy comes in. I call it the inverse pyramid, where we start off by learning the very fundamental concepts and C-Sharp programming, Unity engine and game design using slides and unit documentation, we then immediately use what we learned to enhance our game. But we don't stop there. We keep using what we've learned in more complex and fun ways. We delve deeper than any other course. And to Unity engine, C-Sharp programming, and game design. And the most amazing part is, is that we're doing all of this. But the latest version of Unity was the newest techniques and content and modern game development. And I can say with absolute confidence scores makes it easy for any beginner with 0 coding experience to jump in and start learning how to create incredible games. I've helped thousands of people create real-world games and I want you to be one of those people. So how are we going to do this? Now? We have a lot of sections. I do believe there are like 15 sections, so I'm going to glance over them really, really fast. So we have Section 1, which is the introduction and setup, will download Unity, download Visual Studio, talk about the interface, create our first program and understand how to use this course, which is the review that you are watching right now. We have Section 2, which is the player. We go ahead and add a layer, add animations to learn some fundamental things like rigid bodies in colliders and so on in unity. Then we start looking at scenes will create multiple levels. So the first level where our player will reside is going to be in a town. Then I believe we move to some kind of mountains or something like that. We'll also understand seen management and how it Scene Manager can transition from one scene to the next using the colliders that we've learned previously. And then we are going to learn about maps and center machine. So we are going to use tile sets to create our own maps. And you are going to create your own maps. You're going to add your own labor for the game. And we are going to use one of the latest techniques and unity, which is Cinna machines to allow us to follow the player as he moves around the NADPH. Then we are going to add Doyle of the organic because what kind of RPG doesn't have a dialogue. So we can interact with different emphases and so on. But then look into the player stats. So as you know, in every RPG would have the strength, defends the healthy mono and so on and so forth. You'll understand how we can create all of this and this is very important. This section right here as well, where we delve deep into C Sharp and things start to get a little bit complex, but don't worry about it. I will take you through each step very easily, so you won't have to get confused. Next, we have the Section 7, which is the menu system, because obviously we need some kind of menu where we can go to the items, to the character stats to maybe we want to just save and load and so on. Then we have the inventory system, obviously because as we move through the world will learn how to create items, how to pick up items, how to add to each item that all stats and add them to the inventory that we've created in the menu system will add a money system. And by my system, I mean, we'll predict a bit consistent if you're not familiar, don't worry, we'll talk about that also. And we'll obviously have shops where we can buy certain icons instead of just picking them up and the wild, and they can also sell them. We'll talk about questing because obviously every RPG VIP role in RPG, role-playing game, RPG is obviously where you have quests to complete. We'll have the save and load will learn how play of traps work in detail. And we'll learn how to save load and all of that good things. And the save and load will be applied to the inventory, to the items, to the money, to the player stats and all of that. This is what I meant when I talk about the inverse pyramid. So we've learned the basics we've created. Let's say we've learned a bit of C-sharp. It. Then we learned how to create money and inventory and whatnot. And then we use the player prefs order to combine all of that together. So this is what I meant by pyramid. You start off with the basics and then we keep building on top of all of that. Then we'll also add music and sound practice, because obviously what games it doesn't have used, it really lacks flavor and character if there is no music and sound effects. And finally, the last four sections are personally my favorites because we are going to build a battle system. We'll start off with the regular battled system where we are going to lay everything out and start certain battles and load enemies and the players until that battle. Then we'll see how the enemy can attack and be in section 4, intangible, see how the player can attack. And finally, we are coming to see how we can kill off enemies, kill off layers, and the Bethel give reward, awards, and so on and so forth. So what should you expect by the end of the scores? You'll become a master problem-solver. You'll understand the fundamentals of coding and learn how to program games, just like the ones you're seeing on the screen right now. You'll also have the chance to flex your game developer muscles because with every video there is a mini challenge for loop completes. And even if you can figure out how to do the challenge, Don't worry, I will be there to help you ethical tried and complete the challenge with. Everything in our gain will be configurable. So you can tweak, play around and give the games and individual and special feel about. So you'll be putting your own creativity into it and really making it your own. I'm so excited to get started and hope you are too. This is the perfect time to start learning how to code. So dive in with me and I will help you along every single step of your game development journey. And I'll see you in the next video.
2. Section 1: How To Use This Course: Welcome back, My favorite game developers. And this video, actually, and not in this video. I've created this video in order for us to maximize the potential of learning from this course. So I want you, I want to guide you through a couple of steps that we can use in order to fully squeeze out all the learning energy from the course you're currently taking because you've already, you are already spending your time here. So why not maximize it? So the first thing that we are going to understand is how the Q&A works. So as you are watching the videos, you're looking through them, maybe something comes up that should not fully understand. So what you can do is you can go ahead and slide into the discussions right here. And you can see that you have multiple options. You can either start a conversation, ask a question, or you can simply just share a project. So in here, you can ask me any question that you want. No question is of limit. But there is a small step that you need to do before you ask me a question. And that is, go ahead and do your own research. Why do I ask you to do that? Well, because sometimes when you stumble upon a problem and you go ahead and look for a solution yourself, and then you either find it or you don't. And when you come back and ask me the question, it's much easier to understand. Why is that? Because you've already went through a couple of suggestions, maybe none of them were suitable. But as you go along finding the solution to your problem, you have gained a lot of knowledge. And when you come to me, when you ask Michael and we go through together finding of the solution, you will understand how everything clicks and later on, when you maybe come upon the same problem or maybe you see this problem for another student. You can help them out and it's much easier. And finally, whenever you do find a solution to your question at your question and add a salt prefix to it because other students might have the same problem and they will find a solution for their problem if they see the solved prefix behind it. And finally, before I leave, you just want to say one thing that there is no question of limit. There is no stupid questions, there is no dumb questions. There are only non professional game developers. Nobody was born a professional. We all have to learn through trial and error. You wouldn't believe how quote unquote, my questions were dumb. Because i, o, I'm, I wasn't born a professional in unity took me years of practice, trial and error or asking questions, Googling things. So this is a process. Don't worry, don't be afraid, don't be insecure about some of the questions that you might want to ask. Be brave enough to go look for a solution if you don't find one, not worry about, just leave a question. I always, always answer all of my students and we always delve as deep as needed in order to find a solution to any problem. And now let's talk about the Discord server. And this is where you can go deeper into the community that we've created here on WMD game dev. So you can go either to the link in the description of this video or you can visit my profile and find the link somewhere in there. And I do recommend that you join the discord. Why? Because most of the time it might take me a couple of hours in order to reply based on where are you from. So maybe our we live in different time zones. Maybe when you do ask me the question, it's midnight and you need a solution fast. I might be sleeping, I might be not able to get to my computer. So it's very beneficial for you to join the discord channel that we've created. And let me just show you the score channel right here. This is the beginning of our discord channel. You can see that we have the general community. We have the C-sharp chat, we have the game design chat, we have the show off your game. We have the general game development questions. And you can see that we still don't have anything in here because it's fairly new as I'm recording this. But later on, when you go in here, you'll notice that there is a huge community of people waiting to help you and maybe people waiting to get help from you. And it's very beneficial to try to solve other people's question. You wouldn't believe how much I've learned from just helping other people. And you can see here that we have multiple courses. These are all the courses that double m gamma game down has or I've created. And we can see also we can share memes and here we have general game discussions, AAA games, I don't know whatever you like to play. We can discuss them in here and the social channel or category and so on and so forth. So I do recommend that you join our discord server. It's very fun. We are going to have a lot of fun there. And that's it. That's all that I wanted to say about Discord server. Now, let's move on to the challenge slides. So what are challenged slides? As you move through each video, you will notice that at some point, I'm going to tell you to pause the video and start the challenge. So when you see this slide, you'll wait for me to finish all the points and then you have to pause the video. Why am I emphasizing the word, have a boss? Because it's much better to learn by doing and not by just watching many courses that I've learned from that I personally took where I felt lacking in the Department of doing so. You just sit around, you watch somebody created again. Okay. That's very good. And now it's over. Okay? And then you finish the course. And after a couple of weeks, you notice that you don't actually know how to do anything. So the challenge slides that I've created is extremely important because you at this point start doing instead of watching. And even if you can't figure out how to do the challenge, Don't worry about it. I will be there to help you after you've tried and help complete the challenge with you. So you are never left alone. And in addition to that, just like looking through answers to your questions before asking in the Q&A, when you do a challenge, you stumble upon multiple variables that you might not have considered before. And when you see how I complete the challenge, you will have it ingrained much better in your head when you encountered the same problem when you do start creating your own games. And now let's continue on and finish off with the course structure. Now, we have a lot of sections. I do believe there are like 15 sections, so I'm going to glance over them really, really fast. We have Section 1, which is the introduction and setup, will download Unity, download Visual Studio, talk about the interface, create our first program and understand how to use this course, which is the video that you're watching right now. Then we have Section 2, which is the player. We go ahead and add a player at animations and just understand how everything is going to work with learn some fundamental things like rigid bodies, colliders and so on and unity. Then we start looking at scenes will create multiple levels. So the first level where our player will reside is going to be in a town. Then I believe we move to some kind of mountains or something like that. And then so on and so forth. We'll also understand seen management and how a scene manager can transition us from one scene to the next using the colliders that we've learned previously. Then we are going to learn about maps and cinema machine. So we're going to use tile sets to create our own maps. And you are going to create your own maps. You're going to add your own flavor to the game. And we are going to use one of the latest techniques and unity, which is Cinna machine to allow us to follow the player as he moves around the map. Then we are going to add dialogue or gain, because what kind of RPG doesn't have a dialogue? Seriously, we'll need to add a dialogue system into our game so we can interact with different embassies and so on. Well then look into the player stats. So as you know, in every RPG we have the strength, defense, the health, the mana and so on and so forth. You'll understand how we can create all of this and this is very important. This section right here as well, where we delve deep into C-Sharp and things start to get a little bit complex, but don't worry about it. I will take you through each step very easily, so you want to have to get confused. Next, we have the Section 7, which is the menu system. Because obviously we need some kind of menu where we can go to the items, to the character stats to maybe we want to just save and load and so on. Then we have the inventory system, obviously because as we move through the world will learn how to create items, how to pick up items, how to add to each item their own stats and add them to the inventory that we've created in a manual system. We'll add a money system. And by money system, I mean, we'll create a Bitcoin system if you're not familiar, don't worry, we'll talk about that also. And we'll obviously have shops where we can buy certain items instead of just picking them up in the wild, and we can also sell them. We'll talk about questing because obviously every RPG, the role in RPG TR for role-playing game, RPG is obviously where you have quests to complete. We'll have the save and load will learn how player prefs work in detail. And we'll learn how to save load and all of that good things. And the save and load will be applied to the inventory, to the items, to the money, to the player stats and all of that. This is what I meant when I talk about the inverse pyramid. So we've learned the basics we've created. Let's say, we've learned a bit of C sharp. Then we learned how to create money and inventory and whatnot. And then we use the player prefs and order to combine all of that together. So this is what I meant by pyramid. We start off with the basics and then we keep building on top of all of that. Then we'll also add music and sound effects because obviously what game? And it doesn't have a music, it really lacks flavor and the character if there is no music and sound effects. And finally, the last four sections are personally my favorites because we are going to build a battle system. We'll start off with the regular battle system where we are going to lay everything out and start certain battles and load enemies and players into that battle. Then we'll see how the enemy can attack. And the, in Section 14, then we'll see how the player can attack. And finally, we are going to see how we can kill off enemies, kill off layers, and the battle, give reward, rewards and so on and so forth. So with that all said, I just want to tell you that the most important thing into scores is for you to maximize as much as you possibly can. All the information that is in here, you've already took the time to start the scores. So my couple of tips that I want to give you. First of all, whenever you encounter a problem to your own research, if you don't find a solution or you don't find a suitable solution to your problem, make sure to ask a question. There are no questions of limit, none at all. Third tip is to join the Discord server. It's very important to join the community to have this feeling that you are not alone in the battle, the battle. And think where is the fourth tip that I have is to follow through till the end. So you will start off by learning the very basics. Maybe you already have a bit of knowledge and unity. If you do, maybe some of the sections will seem a bit stagnating because I go through every step very, very carefully. Because a lot of, let's say, maybe you are one of them. You have maybe no idea how C-sharp works. You have no idea how it works. So you do need that extra care and slowing down. So if you are already familiar with Unity, will see sharp. Some of the videos might seem a bit slow, but understand that it's very important for other students also in the field trying to learn from scratch. So with that said, let's not waste any more time. And let's move on to the next video.
3. Download Unity & Visual Studio Step-by-Step: Welcome back, my fellow game developers. In this video, we are going to be downloading unity and stalling good and integrating with it the Visual Studio tools that we are going to need for the scores. So let's get started. First thing you need to go into Google and then go, go simply type in right here, download Unity. It's as simple as that. When you type in, you will get a lot of suggestions. So make sure that you find the one with the Unity 3D.com and the get unity of course, and click on the download Unity, which will open this page right here. So in here you will need to download Unity Hub if you have never before used Unity. Now, what is Unity Hub? Unity Hub is like a place where we will keep all of our versions of Unity and also all of the projects that we make. Now before Unity Hub, our project will be all over our computer, somewhere in different directories and so on. So the Unity Hub really makes it much easier to go through your project and really have, if really good organization. So make sure that you download Unity based on which operating system that you have. So if you have the macOS, you need to make sure that you download the Unity 40 macOS. And if you have a Windows 7, then you download it for Windows 7. So simply click on download Unity Hub. And when you finish downloading, Q should have this installation folder right here. When you double-click on it, it will ask, do you want to? Yes. So you continue on, you click on Agree, you choose the destination where you want to put your Unity Hub. And then you start the installation. Now because I already have Unity Hub installed, I will not install it again. So make sure that you install everything and I'll see you in just a bit. Oh, okay, welcome back. So if you've installed Unity Hub correctly, you should get a message or a window right here that looks something like that. Now, we don't have any projects yet, but this is where our projects will all be present and we can access them at our leisure. Now, before you continue on, Unity will have to make sure that you have an account. So this is my account right here. I used my Google Gmail to create an account on Unity. You can either create a new account or you can also use your Gmail or Facebook. I'm not sure if they allow that. And once you've created an account on Unity, you can go right here into the installs. And this is where we download different versions of Unity. Now, for this course, I'll be using the latest version of Unity that we currently have. Now, if you want to install a new version of Unity or any kind of version of Unity, simply go right here into the ad. Click on Add. And in here you can see that we have different types of unity that we can install. Now, first of all, we have the recommended releases. These are the ones that have already been tested and thoroughly tested and they work perfectly. But you can also go and look for the official releases. Now, we are going to be using this version right here. And this is a very good version. You can install it. And you also have the pre-release is now press releases are do work the same as the official release and the recommended releases, but they are sometimes a bit buggy and you may encounter a couple of bugs on the official releases. There also might be able to bugging issue, but they are not as evident as in the previous releases. You may not encounter any problem, but I would recommend that you use the official release because they are newer than the recommended releases and less bulky than the pre releases. So download the latest version that you have on your computer. Or currently maybe you are from the future and you have a newer version than me. So download the latest version. And don't worry, this course works or the project that we are going to create will work on any version of Unity and the future. Now, we are going to click on Next right here. And this is a very important part of downloading and installing Unity now. And here we have modules, and these modules are like add-ons to our unity that allow us to create games on different platforms. So for example, in here you can see that we can now load modules for different platforms. So for example, if you want to create a game on Android, you can use the module for Android. Or if you want to create a game for the iOS or icons and so on. You may also be looking to create games for Linux or Mac OS or what. So, based on what you want to create, you can choose one of these model modules, or you can just wait later on, you can download these at any point. You also have the documentations which I recommend you download. These documentations are the Unity documentation and they are very important. Maybe sometimes you want to look up certain things. And finally you have the language pack. And maybe if you're Chinese or Korean, I'm not sure what these are, honestly, I have no idea. Maybe you can use one of these language packs. But the most important thing, and you need to make sure that you have the Microsoft Visual Studio Community 2019 or newer installed with your unity. Because we are going to be using Visual Studio to code everything, everything, and all the behaviors of the objects that we create immunity. Now, this is all you need to do. Simply click on Next and you will begin the installation of your Unity. So with that said, it's time for your first challenge. And your challenge is going to be to download Unity and Visual Studio. So download Unity Hub, just like I showed you, make sure that if you have a Mac, you download the Mac version. If you have a Windows, you download the Windows version. Then you need to download the latest release. And finally, make sure that you also download Visual Studio with Unity. So pause the video right now and go ahead and download unity with Visual Studio. And in the next video we'll simply go over the interface of unity and Visual Studio you just saw we can get over our initial fears. So I'll see you in the next one.
4. Unity & VS 101: Okay, so welcome back to another video. Let's see what is unity? Unity is a cross-platform game engine development developed by Unity Technologies. We'll use Unity to develop our game. So what does Cross-platform means? It means that we can use it on different platforms. And it's a game engine. And what game engine is, it's a environment for us to develop games and add physics and add different things to create our game. So let's check out what Unity actually looks like and I'll explain a couple of things on it. So This is unity. First of all, we have this toolbar right here up above everything. And this provides access to the most essential working features. On the left, we contains the basic tools for manipulating the scene view and the game objects within it. In the center we have the play, the pause and the stub Control button. And the buttons on the right gives you access to the Unity collaborate, unity Cloud Service and Unity account, and will not get much into that. On the right side of those, we have the layer visibility unit menu. And we have the editor, which provide some alternative layouts for the editor window and allows you to save your own custom layouts. So if you don't have the same layout as I do, you can simply click right here on layout and you can choose the default layout. And this is the default player that we have. It's the projects right here and inspector and everything. Next thing we'll talk about the hierarchy window right here. It's a hierarchical text representation of every game object in our scene. So each item in the scene has an entry in the hierarchy. So the two windows are inherently linked. The next hierarchy reveals the structure of how game objects attached to each other. So right here we have the sample scene. And if we click on that, we have the main camera under it. And if we add another game object, it will also show up right here. And here is the inspector, as you can see on the right. This is the window inspector and it gives, it allows you to view and edit all the properties of the currently selected game object. So if you don't select the game object, we don't see anything. When we click on Main Camera, we have these different windows right here, and the layouts and counter contents of the inspector window changed each time you select a different game objects. So now we don't have a different game object, so we'll just settled for the camera. Next. Then we have is this scene view right here. And the scene view allows you to visualize and navigate and edit your scene. The scene view can show you either a 3D perspective or a 2D perspective depending on the type of project that you are using. So in scores will be using the 2D project view, but you can also write here, click on the to the button and it will go 3D. As you can see, we have this 3D view but we won't be needing, it will simply go into the 2D mode. And finally, I want to talk about the project window right here, which displays your library and assets that are available to use in your project. So when you import assets into your project, they will appear right here. So for example, for now we don't have any assets, would only have the scenes folder. And inside the scenes folder, we have this sample folder. So this is a quick overview of unity and what all those panels and gadgets are. We will, of course, delve deeper into them as we go through the course. But now I want to talk about the, something very important and that is the Visual Studio. So what is Visual Studio? Visual Studio is a Microsoft Visual Studio. It's used well, it's developed by Microsoft and it's an IDE. And IDE is an integrated development environment. And what it does, actually, if you ask me in visual Studio, will help us write the code used to manipulate game objects in the unity and using something called scripts. So how to use Unity with Visual Studio? So we need a way for unity and Visual Studio to communicate. But they do not simply do that. We need to add something to it called the dot CSS file, and that is our scripts. And those scripts are, we actually take those scripts, we attach them to game objects, and using those scripts will be able to add behavior too different. Kinds of game objects, and we'll see that very, very soon. So let's go into Visual Studio and see what it's all about. This is Visual Studio. And maybe the first time you open it up, you'll have different panels right here on the right and the front windows right here on the left. Feel free to close all of them. And don't worry about what happens next. Of course, you won't have this the first time you start up Visual Studio, but you'll see it soon enough. And I'll just introduce you to a couple of lines of codes right here. So let's zoom in just a bit. And right here on the top you can see that we are using system collections. We are using stamp collection collections generic. And most importantly, we are using the Unity engine. What are all of those? Well, those are called namespaces. And basically these are libraries that give us the opportunity to use different kinds of coat. So for example, Unity engine, which we added right here, allows us to use for the start method and the update method and different engines to create games and make it much easier. And we simply write here using Unity engine. And it saves us a lot of gold and gives us the entire library to use. Next thing we have the public class class name. And this is the, actually the className, which should be right here. It will be the script that we've talked about and it will be attached to a game object. And it will encompass all of the code that will change the behavior of our game object and sidewall game and mono behavior is a base class and it's actually these two mean that it inherits from the mono behavior, which allows it to use different kinds of manipulations and engine and physics and so on and so forth. And next thing we have is the start and above it is something called the common. So whenever you write code and add these two lines right here, it will comment things out and comments actually don't get executed in the GOP, the code, code, the code and they are perfectly safe. So it start, start is called before the first frame update. So as soon as our game starts, the start method, and this is called a method we'll start to execute. Next thing we have the update, and the update is called once per franc. So every frame that we have in our game, the update is called. So start is typically used to give the initial properties or configurations to certain objects. And the update is used for objects that are moving or change every frame. So if we have a car, for example, and start, we can give it the color, the name, the speed at which it can go. An update will be moving the car, will be making the jump, will be making the car go faster, maybe increase its speed. So you get the basic idea of Visual Studio and now it's time for your challenge. Your challenge is to go make a mass. So open Unity, create a project. And if you don't know how to create a project, we'll do that in the next video. And when you're finished, after you go make hay mass, go to the next video and we'll make our first code and gets started. So I'll see you in the next video.
5. Your First Code: Welcome back, my fellow game developers. In this video, we are going to be creating our first code and our first game objects. So as you can see right here, we have a game object called Hello World in our heart and our hierarchy. It's present right here in our scene, although we don't see it very well. And we have the script right here attached to it. We've also created the script criteria in our project. And in console. If we click on Play, we actually get a message that displays Hello Michele, which is me. In your case, it will going to be displaying your name. So I'm very excited for this video because it's our first delve into Unity world. So I hope you enjoyed the video and I'll see you in just a bit. Okay, so first thing we're going to do is we're going to open up the Unity Hub. And currently you have no projects here, which will change in just the first thing we'll do is click on New right here. And we'll need to choose a template for our game. So we'll be creating a 2D game, not a 3D. And these are different options also for different project pipes. Next thing we'll need to add a project name. Feel free to name it what ever you want. We'll be calling it for now, the Hello World, the project. And make sure that you choose a location for your Unity projects. So we'll click on this one and let's go back and save it inside of the Unity projects. So select the folder and now we have a location for our game. You need to do. All you need to do right now is click on concrete. So click on Create and Unity will start to create your project. And I will not bore you with the waiting here. I'll use the magic of editing and will simply jump into the project. So see you in a bit. Welcome back. So I hope your project also finished setting up. So this is our scene. If you don't have this kind of seen, as I've told you, you can always go to layout and choose the default layout. And we'll have the same layout, both of us. So before we start, let's first of all at something called the console. And as you can see, even before we start anything, we have this console window right here. And what this does is it shows us the messages. And we're going to use this console window to see the things that will print from our code. And if you don't have it, you can simply go up here in the window, click on it. And just above here, you can see on the general will have the console, so click on it, a window should appear and you can dock it wherever you want. I'm going to dock it right here in to projects. In other thing I want to talk about is in the, wherever you've saved your project. I've saved it in D, Unity projects and Hello world. So as you can see, we have different folders right here. We have the assets, hold our scenes and everything that we create and projects. You can see the assets and project assets right here. We also have the library which automatically created every time we enter a project, we have logs, we have packages, we have Project Settings, all although all of those are details that will not get into too much. And the temporary folder, which we'll discuss later on in the magic tube to the game. So let's go back into Unity. And in here we are going to be creating our skirt. So let's right-click in here. And let's go into Create and create. We can actually create multiple things, as you can see, we'll do a couple of them in our project, but for now let's simply create a C-sharp script. So click on that. And before you do anything, So now don't do anything, leave everything. You will need to make sure that whenever you name a script that you do it with precision because it will cause error later on if you want to try to rename your script. So make sure you name it correctly from the get-go. So we'll name this hello world without any spaces and click on Enter when you're sure that you have decided on the name of the script. So click on Enter and I'll tell you why in just a bit. So as you can see, we have something right here in the inspector. And it took a bit of time and it's because unity needs to compile the code right here. And you can actually see the code in the inspector. And why I told you it's so crucial to make sure that the name of the script right here is defined before we click on Enter as because it is going to be the name of our class. So if you change the name of our script right here, Tick Last name won't change. And there will be an error where unit or the visual Studio will not be able to find the correct script in the project and this will cause errors. So to avoid that, simply makes sure that you name your script correctly and precisely from the get-go. Now, what should we do next? It's very simple. You simply double-click on Hello World and the Visual Studio should open up. And as you can see right here, this is what we've described a couple of maybe in the previous video. So what are we going to do in here? We are simply going to print something to our console and we'll do that inside of stock. So let's go ahead and print. So as you can see immediately, Visual Studio, our great friend starts to help us and it gives a suggestion for what we want to use. So we write the print and it gives us the suggestion. And now you can simply click on Tab and it will finish it for you. And now we open up our brackets and we can see that Visual Studio again helps us. And it tells us that we need to add a object message inside of here. That object message is going to be a string. We'll talk about strings later. But for now, string is a string of characters that we put inside of these two quotes right here. So let's go ahead and add these two quotes a again. And now we write inside of these two quotes, hello world. So is that enough? Well actually, no, because if you see right here, we have this squiggly red line. And if we hover over it, it tells us that it expects a symbol, which is this one. And every line of code in C Sharp, you have to add this semicolon right here. So save that. And now, because we've put it inside of start, as soon as we start our game, this message should be printed on the console. So let's try that. We go back into Unity and we go into console. But if we click on play, as you can see, nothing is being displayed on our screen. Why is that? Because it's not enough just to create a script, you actually need to attach it to an object. So let's create an object. And the way we do that, we simply go into our hierarchy. We right-click on here. We can create a empty game object. Click on that, and now we have a game object. Let's go ahead. We can change the name of that game object. We'll call it. Let's call it hello world object. Click on Enter, and below it you can see that we have the transform. And this transform tells us the position of our game object in the world. And up here we have the tools to manipulate. So if you click on the stool, it can actually put the object up or drag the object down, take it to the left or to the right and put it anywhere we want. And currently we cannot see we don't have anything to represent or game object. We simply have its ordinates and its transform. So let's attach the script of this game object. To do that, you simply click on the script and drag it into the hierarchy and to the hello world objects. So if you click on Hello word object right here, you can see that it has a script just below the transform attached to it. And now if we click on play in the console, we can see that we have hello world. Congratulations, you've just written your first coat and you've just used your first game object to display something to the console. Go rate, and now it's time for your challenge. Your challenge is going to print your own bank. So instead of hello world, you'll need to print your own name. So change helloworld to hello. And instead of those three dots, of course it's going to be your own name. I'll give you a couple of hints. So add your name and size of the dots. Save Visual Studio. Always remember to save Visual Studio, we're using control as go to Unity and click on play and check your console. So make sure it works. Pause the video right now and go do the challenge. Oh, how did you get wrong with that? I hope you tried your best and that challenge. Let's go into Visual Studio. And instead of world, I'm going to delete that and I'll put my own name, which is michelle. So hello Michelle. And we'll just add an exclamation or three exclamation points for the dramatic effect. And to make sure that you've saved your project. I mean your script. When you look up right here, you can see that it has a small asterix attack, as strict as drugs attached to it. And to save that you click on, and that means it hasn't been saved. So a few hold Control, S, click on control. As you can see that the asterisked as trixie disappears, and that means that script has been saved, go back into Unity. And you can see that there is an asterix right here, also next to the sample scene. So save that. And now if we go to console, you can see right here that we have this button clear. Or if you click down, you can see that we can click on Play. You can remove that. Feel free. It doesn't matter. We'll just remove it to see the changes that happen at now if we click on Play, we will have hello Michelle, or hello, whatever your name as my fellow students. And that is 0. So clear that, that strive again, click on play and hello Michelle. Hello, My favorite game developers. I hope you'll enjoy the video and I'll see you in the next one.
6. Version Control 101: Welcome back, my fellow game developers. In this video, we are going to be learning everything about version control, source tree, and creating repositories of our projects. So as you can see right here, we've created a new project and we've downloaded source tree. We now have a couple of commits in here, and we actually reverted something. We've created our initial commit, added a cube, reverted it. We can actually reverse this commit. A can. So click on Yes. As you can see, we can go back to Unity reload and we have our cube right here. We will be learning everything in minute detail. So give me your entire concentration. This is very important. It's an extremely helpful video or lesson and we'll stay with you forever as long as you are committed to becoming a professional programmer or game developer. So let's not waste any more time and let's get started. O k. So version control that and put on my laser version control. It's hard to learn. It's even harder to teach, but I'll try to keep it as simple as possible. And when you get the hang of it, trust me, it's very simple and easy to use. Plus it's an indispensable skill that you need to learn if you are looking to become a professional game developer or even a professional program. So let's get started with what is. First of all, it's a system that is responsible for managing changes to computer programs. So this means that whenever we create changes in our programs, we can actually save those changes at each step of our project. This way, we can first of all check what we did. We can create different kinds of versions where we can go back and change the things that we've created. It allows for a better teamwork. So for example, let's say you have four or five people working on the same project, but each one of them has a different task that they need to create. So version control is a very good way of handling all of this. And why do we need it? Well, why we, we actually use it? Well, we'll use it to remember previous version of our game and have more flexibility to experiment. Usually, game development is a environment where you require a lot of experimentations. For example, you want to add some kind of property to some kind of game object and maybe it breaks your entire project. So you want to always have a previous version of your project before adding this game breaking mechanic. So you can always go back and start fresh from there. So this is extremely important, especially for game developers that always need to be experimenting with new ideas and things in their games and projects. And how are we going to use it? Well, we are going to be using something called source tree, and this is version control. It allows us to create different versions. And its first of all, it's for free. It's very easy for beginners, very flexible, and it has a very simple interface that we can use as beginners. So let's go ahead and download source tree. Let me show you where we can do that. If you open up Google Chrome or any browser that you have, simply go to Google and right in here, download source tree. You should find a link right here, and it should be the source tree. Up. When you click on it, you go right here to their website. If you scroll up, you can see that you have the option to download for Windows. But if you are on a Mac, make sure that you click on here and you download source tree for Mac OS or it will not work for you. So if you have a Mac, download the Mac version, if you have a Windows, download the Windows version. Simple enough. Now, when you finish downloading, you should get this file right here. And when you double-click on it, you should start the installation. Now because I already have source tree, I will not be installing it another time. I will just take you through the process of actually installing. Okay, So this is the first window that will pop up for you. First of all, you need to agree to the license, of course. And you can maybe turn this off if you don't want any e-mails your way from source tree and et cetera at lesson. Next thing you need to do is you need to create an account on occasion, you can go to at lysine and placing as the parent company of source tree can go ahead and create an account there, or you can use an existing account if you already have a Gmail. I personally create one using Gmail. It's much faster, It's way easier and they don't spam you with a lot of emails. Next thing in here, we are going to connect it to an account. Now, this is, of course, we will not be doing this. If you want to host your code on a certain websites like GitHub or Bitbucket. We will not be doing that, so you can simply click here on skipped setup. Finally, while installing source tree will tell you that it is unable to locate get. So in order to complete this, simply click on Download and embedded version of Git and continue on. And then it may also ask you for something called a mercurial. Now, Mercurial is a different system, just like get. It allows us to save different versions of our project. We will not be using Mercurial, so you can simply click on, I don't want to download or I don't want to use Mercurial. And this should be when you finish installing. You should have this right here. And your, well, this window right here when you start source tree, if you don't simply click right here on Create and you should get this window. Now, this is where we actually create our repository. And in here you can see that we have the destination path, the name, and the type of version control that we want to use. Of course we'll be using the GET. We also have the option to create an account, but as I've told you, we're keeping things very simple. It's our first time, so we will not be creating any account. So here we are going to choose which is the destination path of our repository. So what, what is the project that we are actually going to be creating a repository for subsequent versions of. Well, let's create our first project that we are going to be using. So in here that's open up the Unity Hub. And as you can see, we already have Hello World that we don't in a previous video that's click on New. And let's make sure it's a 3D project. And this is going to be our cyber spy 2087. Let's go ahead and create this project. So click on Create. And I, of course, always using my magic of editing in order to speed up this process. I'll see you on the other side. Okay, welcome back. So I hope everything worked out for you. So now we have a new project which is cyber spite 2087. So now that we have our project created, we can actually go ahead and get started with creating a repository. Now, if we go back into our source tree right here, we can click on Browse and we can actually go ahead into Unity projects. And you can see that we have a hello world and we have a cyberspace by 2087. So let's select this folder. It will create a repository under this name. If we hit Create, it will ask a problem. Don't worry about it. Click on Yes. And voila, now we have actually started creating a repository. You have the staged files right here. You have different kinds of knobs. You don't need to worry about any of them for now, just focus on the staged files, on staged files and commit up here. Now, if we scroll down in these onstage files, you can see that most of them are from the library. We scroll down to the end, we can see some of them are Tampa 10 or temporarily. We can see also that we have project settings and these are all the files that we for our project. We also have assets in here for unity in the scenes for example. So this is a repository which is a version of our current project. Now, the problem here is, as you can see, there are a ton and ton of files, and B will not be needing all of them. Well, actually we'll need almost none of them. We will need only a certain kind of files. So we want to be ignoring the library and the temporary temporary files. Why is that? Well, let me show you by opening up the directory of our project. Oh, okay, So this is Cyberspace by 2080 sevens directory inside of Unity project, as you can see up here. So we have the assets, the library logs, packages, et cetera, and et cetera. Now, what is the temporary folder and what is the library folder and why don't we actually need them? So temporary is just a way for unity to open up faster whenever we start the project. And it's always created whenever we open a project. So for example, if I go into Unity right here and I actually close it, you'll see that the temporary file. Will disappear. And even if we delete the library right now, so let's go ahead and delete this library entirely. If we go back into our Unity Hub and open up cyber spy 287. As you can see right here, you saw that the library has been created again and the temporary folder has also been created. So of course, the project should take a bit more time now to open up. But this is evidence that a library and the temporary folders are not necessary for us to always commit and stage. And what do I mean by stage? So whenever we stage our folders, we actually create a commit from them, any version of them. And library takes up a lot of space. As you can see, if we scroll down, it takes up most of the space and we don't want any of them at all. So how should we proceed? Well, we can actually ignore all of the folders that are under the library by simply going and choosing any of the folders that have library on them. Right-click on it. And in here you can see that we have the option to ignore one of them. So click on ignore. And in here you have option to ignore this exact filename, ignore all files with this extension, or you can ignore everything beneath a library, and this is what we want. So click on Okay. And as you can see, everything under library has now been ignored, so we cannot stage it, so we cannot save it to our newer version. And if you scroll up, you might have noticed that we have a new folder in here that is the dot git ignore. And when we click on it on the right, you can see that it has the library. And, and if we double-click on it, we can actually open it up in our notepad and in here we can add the different files that we also want to ignore. So what are the files that we want to ignore? Well, there are a ton and ton of files, but thankfully, somebody has actually gone through all these files and created a list of everything that we can ignore whenever creating version controls or versions of our project. And in order to find that file, you can go again and to Google or the front. Go ahead and search dot git, ignore unity. And you should have this link right here for the github.com. And it will be hosted on GitHub. If you open up this link, it will take you right here. So this is the dot gitignore and it's the unity dot git ignore. And these are all the files that we can ignore when creating versions of our project. You can click on row right here, and it will open up this window or tab. Let's go ahead and select all of them by clicking on control a. We will copy all of this using control C. And we are going to paste it in here in our dot gitignore notepad. And now we have the gitignore notepad filled with all the files that we will not use for our positive 3. We will save that using Control S. And now back in Unity or I mean back in source tree, you can see that when we had the git ignore, everything is ignored. We will stage all of that. And when we stage all of that, you can see that these are the files that are going to be committed. And these would be our initial commitment or our initial repository version of the project. And usually whenever you create your initial commit, we call this the initial. You can capitalize it, the initial, oops, initial commit. And we click on Commit right here. So now if you look on the left, you can see that we have branches under here and we have the master branch. Congratulations, we have created our first commitment. Very nice. Now, let me just show you how we will move further down the line, even though this video has been long enough. But I think we need to get a proper foundation for source tree and version control as we move through our project. So let's say we are in our project right here. And let's go ahead and create some kind of cubes. 3d object. Right-click in the hierarchy. 3d object, create a cube, and now we have a cube. Let's scale it up a bit. So scale it on the x, the y, and the z. Great. So now we have a cube and our scene. And now if we go into source tree, let's save that before we go. And it needs to save it to a certain scene. So let's inside of scenes. This will be our sample scene. Sure. Sample scene, yes, replace it. So we have this sample scene back and source tree. Wait for it a bit, and you can see that we have uncommitted changes. So if we click on them, you can see that the on-stage files are changes inside of the scenes, which is the sample scene. And here you can look in detail what we've created now. It's a bit weird right here, but if you look closely, you can see that we've created box collider. And basically this represents the cube that we've added to our scene. So let's go ahead and stage all of that. We can click on Commit right here and name this added a cube. Click on comment. And now in our master branch, you can see that we have an initial commit which didn't have any cubed. And now in our added cube, we've added a cube. So congratulations. And as a final note, this may look a bit cumbersome. This may look a bit weird, but don't be afraid this is very simple. And more importantly, it's extremely important for us to understand as we move through our project, create versions, versions of it. And if we ever make a mistake, we can actually go back by right-clicking in here, reversing the commit. And yes, we can reverse the commit if we go back and to unity, it will ask us for a live reload. We wrote, we reload, and now we don't have the cube or any game breaking mechanic that we've added along the way. And now it's time for your challenge. Your challenge is going to be to download and setup source tree and the ignore file. So download source tree and stall and setup everything. Create your 3D project in Unity Hub, setup a repository for it and source tree, nor the library files and get the dot ignore file and add it to your repository, create your first commit, and then create your second commit. You can even go ahead and try to maybe play around with a couple of things. Add a cube, reversed the commit, see what happens. Get comfortable with source tree. And if you're having a bit of trouble, you can pause the video on this list of things that you need to create. And you can also always go back and watch the video and see how I made everything and follow along with me step-by-step. So see you in just a bit.
7. Legends Of Conquest Game Design: Hey, my fellow game developers. So before delving into the scores and the way we're going to be creating it. I thought it would be a very good idea to talk about the game design of our game. So I always recommend that you do this. And the way you start off by building a game as just making a very, very, very rudimentary and simple concept of your game. So I decided to use a daemon as a sprite. We'll see what sprites are in just a bit. And he's going to be called I believe I called him Jimmy at some points. So we're going to have the gym edema. And I just drew a road, the road that we are going to be walking in, we will have grass in here, like the grass. We might have a caves for some entrance. We might have a cliff and here, and this is the basic layout of the levels that we are going to have. We will have also a bit of water. Now let's talk about the characters and our game. We have M0, which is the demon. We have a shopkeeper. Maybe we'll even create a place for the Jimmy demon to go in into a shop where we can buy items, sell items, maybe even get quests, have a bit of dialogue. Then we have quest givers or just MPC's that we can talk around and find quests where we can get them. So we can find some kind of beautiful red haired lady where she tells us that her maybe son is missing. So we need to go and find them. Then we also have these monsters and here are the bad guys. And I drew them. Maybe we can find them inside caves or dungeons or on top of hills. And this blue square in front of him is where we actually start the battle. So if we walk into the square, we immediately start a turn-based combat that we'll talk about in a bit. We can also find items on the ground, for example, a Golden Shield. Or we can get these items after winning a battle, or we can buy them in the shop. So all of that is available to us. And we can see in here that we have these black squares in here and what do they represent? Well, they are a way to go from one scene to another. So we're going to create a tile map. We'll discuss what pile map is. Don't worry about that. Where we are going to lay out everything. But as you know, we cannot lay out the entire game on a single map. So what we'll do is we're going to transition from level to level using these roads and going out and front. Let's delve a little bit deeper. So let's talk about turn-based combat and what it is. I'm going to glance over just to show you a couple of games that implement this, we will delve deeper when we get to that section and our gain. You can see in here, this first one was the Final Fantasy game. I believe. This is a very new game. I believe not very new, but in the recent years created and it's very highly acclaimed and really sold a lot. So I'm just showing you the different kinds of turn-based combat modern games. So you don't feel like, Oh, this might be boring actually, no, it's still used in modern game development. And you can see in here, this is the way we dissect a tile map. So you can see that each of these are tiles that we use for our game to draw them all. And this is for sewn up five. I believe it's a fairly new game, has very high acclaimed and it's turn-based combat where each player takes a turn to attack some kind of enemy in front of them. Let's move on. Let's talk about the legends of conquest game design. So what are the core mechanics of our gain? It's going to be walking, interacting, and the turn-based combat. What do I mean by walking and interacting? Well, walking is fairly simple. It's understandable. Interacting is interacting with other NPCs, interacting with the shopkeepers and I'm just going to lay everything out. So interacting with shopkeepers, interacting with maybe hidden items, interacting with quest givers, interacting with the enemies, and the turn-based combat is also a core mechanic of the game. We'll also talk about the core gameplay. So the core gameplay is taking quests, defeating monsters in caves, earning money and experience. And we also have upgrading our player and our weapons. So we will create a system where we have player stats and we upgrade them as the player earns more experience and so on. So this is a small scene next to the water with a boat. And that's just it. So let's talk about game story. And you might be thinking, Well, why should I have a game story while you're working on a project? If you don't have a game story, if you don't have. The big picture of your game, you won't know where you are heading. You will find yourself lacking motivation as you move through your course. And you will see that it's slowly, slowly, but surely leaving your soul no more motivation. So what is the game story of our game? You are a demon from the depth of hell in search of your Dark Knight and brother who was captured by the Emperor. Your mission is to kill monsters in caves that haunt villages in the empire. And I've stopped here, but you can expand on this a lot. So you might think that you kill monsters in the villages for the empire, because you want the emperor to keep your friend save. Maybe you want to save him at the end. Maybe the emperor becomes some kind of demon or some kind of dragging at the end and you need to defeat him after saving your friend from whatever he was, the Dark Knight, we actually use one of them. It's not batman, a dark night that we found a sprites for. So you can see, for example, we have a dialog system where we talked to the shopkeeper. We she tells us she's a healer. She tells us, hey, I'm a healer. And we also have different kinds of environments. So we use multiple sprites sold in here. This maybe isn't some kind of outskirts where you need to find some kind of quest, maybe find some herbs for the healer or whatnot. So let's keep gone. Finally or not. Finally, I'll know Let's talk about the technical requirements. So we are going to have a tile set for the background and the solid objects. We are going to have inputs from the keyboard controlling our gain. We're going to have a follow cam. I'm just going to open all of these up. We're going to have where were we follow cam that will follow the player using something really, really cool. And that is adding a praying through our camera, which is very weird I know, but that allows us to use Cinna machine. So you can see this is another different environment where we have lava and this monster. And here we will have clear stats. So we will have dexterity, defense, HB, Manor, experience, and so on. All of these will be stamped with a leveling up system. We will have a dialog system, as you saw on the previous slide. We will have a quest system. We will have an inventory system, which is going to be a very fun part of the course because we are going to use all of our knowledge in C-Sharp. It's going to be so fun, you will learn so much. And then we have the shop and money, which is also going to be a very complex, but sometimes taking two simple ideas and combining them to work together, which is the inventory system and a money system that will create, to work together, to create a shop. It's going to be a very, let's say, challenging creation to do. And finally, we have the turn-based combat system that we are going to be delving so deep into and learn so much. And so let's talk about gameplay futures. And I'm going to open everything up so we can see the picture at the end. So this is a photo that I tried to take a screenshot of the turn-based combat. So you can see that we have the names of our players with their health bars. They're minor bars. You can see that we have options to attack, to use magic, to use items, and to run away. And you can see we'll have multiple types of players. And this is the dark night that I was talking about. And this is some kind of fellow traveler, a grim a skeleton that you find along your way and he agrees to help you with your battles. So this is a master major that I found and this is a warlike. And all of these are sprites that I found for free on a website that I will be talking about and using a lot. So what do we have? We have the Conqueror movement. These are the gameplay features we have walking will have walking in multiple ways. So I go back to show you. So we have, for example, the demon facing the front. But in here, for example, we have the demon facing the left and the right and upwards. So this is actually a feature or a mechanic if you want. In our game, we have interacting with MPC's. This is also a very crucial part of the game. So what are the interactable? We've talked about how we can move through levels or scene. You'll see what scenes are when we get to the course. So we have area exits. So these are the areas where we can exit from N2, other areas, we have battle zones. This is where I talked about where we have some kind of enemy in front of us and we walk into the battle zone and we start to fight them. We have items on the ground that we can pick up. We have MPC's for quests or to shop with. We have a start and end point, which is very important. We'll have an exit area point that the demon walks through to get to one area to the next. Also have the pickups, which are the items on the ground. We have multiple items also, and you can add your own. That's the most beautiful part of all the scores that you can add your own items into this game. We currently use a silver acts, a golden axe, a silver armor, a golden armor. We have monopole oceans, we have HP portions and so on. So finally, I'm going to issue you a challenge, and that challenge is going to create your own games design. So you'll need to figure out a story for your game. I know you might be thinking, seriously. I just want to learn how to code. I just want to create this game, please. Michael, leave me alone. No. You need to figure out a story for your game. Trust me, when you do figure out a story, this course will be so much better. And I'm not here to teach you how to create. Again, I'm not here to teach you how to code in C Sharp. I'm here to teach you how to become a game developer, A-Master, problem-solver. So the first thing you need to figure out is the story behind your game. Then I want you to find out the game mechanics. You want. Maybe you want to add jumping, maybe you want to add running. Just put them on the site. Even if you're a beginner, just add everything that you would love to have in your game. Maybe you can't implement it right now. Maybe we don't implement it in our game. But as you progress through your game development journey, you will see that by the end of the scores will have all the tools to create everything that you want for your game. Then you'll need to download your own sprites and by offsets, make sure you have foreground and background. If you want to. Wait a bit for this point right here, when I show you the website, it's open game art. It's not like some secret website or anything. It's open game art. Go find your own sprites. Go find your own characters, enemies, monsters, NPCs, dial sets, whatever you want, go find your own. I really, really recommend that you do need to figure out what features you want to add. Maybe you want to have something different than simply items on the ground. Maybe you want to have some hidden items. May want to have chests that open up and find the items. Go crazy fun your own features. And I guess that's it. We are wrapping up our section. So I'm going to let this challenge in here in front of you. I want you to take the time to create the story. I want you to take time to write down the mechanics you'd love to have in your game. Get creative, even if you think that you have no skill, do this, just write them down. We will be dealing with everything in this course. So let's not waste any more time. And I'll see you in the next video.
8. Section 2: Setting Up Sprite Sheet: Welcome back, My favorite game developers. In this video, as you can see, we've created a new project called the legends of conquest to the RPG. Yay, have very exciting. This is the best part of creating projects. We next added this background image. We added our little daemon right here that will call later on. And we also talked about sprite sheets and sprite renders. We also talk about a very exciting, a very nice website where you can find all of these for free. So let's not waste any more time and let's get started. Oh, okay, so first thing we're going to do is we're going to create a new project. And here we are going to make sure that it's a 2D game. And we're going to call this legends of conquest to the RPG. And make sure you find the proper location. I am going to save it inside of Unity projects right here. So hit Select Folder. Now it's saved in Unity projects. It's called legends of conquest to the RPG. And we're going to create the project. And I'm going to skip this part just because I don't want to bother you with all the useless time. Oh, okay, welcome back everyone. So now that our project has been created, let's start adding things to it. First of all, let's add a kind of background just to have a place for our characters to walk in. So I've prepared something called the background image, and you can simply drag it right here into the assets. And now we can simply drag it over our c. So as you can see, it's a bit small. Let me just re-center everything right here. So the position is on the 0 on the x, 0 on the y, and 0 on the zed. And as you can see, if we run the game right now, it's a bit too small. Now what we can do, we can increase the scale, but a, another very nifty trick that we can do, a fee click right here on the image. You can see that the pixels per unit is 100. Simply make this 30 to hit apply. And as you can see, the image grows larger. And I'll explain later on what pixels per unit. Now the next thing we're going to do is we're going to add our character. And for that, we are going to be using something called a sprite. Let me just explain what a sprite is. So what is a sprite? So this is a sprite of our character, the ones that we are going to use. And this is also a sprite of the ground that we are going to use our game. So a sprite is a 2D object. They have graphical images on them called textures, just like you can see in here, these are textures on a 2D object. And they are used by adding a component called the sprite renderer to a game object. So let me show you how that works. First of all, let's go back into Unity. And let's go ahead and grab our character right here. As you can see, we have many options. So I'm going to choose the walk vanilla right here and added into our assets. So let's hit Enter. And before we continue on that, we just changed the layout in here from the default one to the two by three. And this will help us much better. Grab the game and look around as we can see the scene and the game below it. Because this game will be very focused on how everything looks compared from the scene to the game. Okay, great. So next thing we're going to do is we're going to click on the walk vanilla right here. If you press the little arrow, you can see that all demons are mashed up together. So if we double-click in here, you can see that all the demons are on the same image, but we don't want that. We actually want just this image right here in order to display it. Because if we just add it right now to the scene, you can see it's too small and they are all packed together. So let me just delete this. So the way we're going to do this is first of all, we'll click on this image. We can look in here and the inspector, we can first of all maybe make this 32 or will change this later on. Let's keep it 100. We need to change these private mode to multiple. Will need to change the filter mode to a point. No filter will apply all that. And now when we click the sprite editor, as you can see, we can start slicing our sprouts. If we look up here, we have the option to slice this automatically. But if we tried to slice this automatically, you'll see that not all the squares are the same size. And this will be a huge problem later on when we try to animate, because as you can see, this is the walking animation. We have multiple tribes. If they are not the same size, it's going to be a bit hard. So what we're going to do is we're going to change from automatic to grid by cell size. And if we hit this slice key right now, you can see that it creates a very neat slice of our big sprite sheet. So you can see that every single sprite or slice from the sprite is the same size. And this will help us tremendously electron. So now we can hit the slice, we can hit the apply. And as you can see, each slice has a specific name. Now you can change the name of the sprites to walk a right one, for example, but I don't think it's very necessary. You can also tweak the size of the slices right here, but I think this is good enough. So hit Apply again. Let's exit out. Now if we hit the arrow key, you can see that we have the individual sprites right here. And we can start by dragging this one, the main one, and putting him on our tile map or our background image, as you can see, here, is not visible. Where is our little demon? Well, he is here, but if we move him from behind the background image, and you can also see that he is very, very tiny. And this is where we can change the pixel per unit. Let's say 32 had applied, and now he is the correct size. If we move him back in here, you can see that we can see him on the ground. We can also even make him bigger, maybe make this 16 hit Apply. And he disappeared again. Let's move him from the background. Okay, there we go. I think 16 is a good enough number, but still you can see that we cannot see him from behind the layer. And this is a problem that we can solve this right now, if we look in the sprite render, this is a game object that has a sprite renderer on it. If we, for example, turn off the sprite renderer, you can see that the image no longer rendered or the sprite is no longer rendered. We can click on here again and return back the sprite. And we can change the order of the layer right here, 21. And now if we move him, we can see him in front of our image. Because the background image, which also has a sprite renderer that we can turn off, has an order layer of 0. If we put it to two, you can see that the demon disappears, but this is not a very good solution. We will solve this in the next video where we will create sorting layers. But before we do that, I have a challenge for you. And your challenge is going to be to go ahead and create your own player and worked. So explore a website called Open game art that me show you. So this is open game art.org and it's an amazing website where you can find a lot of free assets to use in your 2D games, 3D games. And you can also find the music and sound effects and much, much more. So for example, this sprite sheet right here, this, Let's say tile set. I got it from the author Savini the New York. I'm not sure how to pronounce this, make sure to check them out. I also got my demons right here from William Thompson as j, also on open game art.org. It's an amazing website. I recommend that you explore it and you find your own characters. Make sure that the character that you find has these walk animations on him. So back to our challenge. Next thing, you need to find some characters and sprites that suit your style. Maybe you don't want to have a demon chasing around a village. I admit this was a bit of a clumsy idea, but I wanted to try something new. For moving to the next video, find your own sprites, have some fun, enjoy your time. This is, as I've said in the first video, this is all about creating your own game and adding your own flavor and style to the game. It's not about just copying what I do and what I find good for the game. You need to add your own flavor into it. So take your time, find goods sprites, explore open AND gates are that.org, maybe you'll find other websites and I'll see you in the next one.
9. Sorting Layers: Welcome back, My favorite game developers. In this video, we are going to be learning about sorting layers. So now if we click on the background, you can see that the sorting layer is the background. The player has his own sorting layer, the player layer. So let's not waste any more time and let's get started. Oh, okay, so as we've said before, we can actually use the order in layer to change the order in which our sprites are rendered. But in this video, I will show you another much more sophisticated way of doing things. And first of all, why do we need this more sophisticated way? You might be asking, Well, Michael, I can just simply add another object, put it to, let's say three and then four, and then five and so on. But what happens if, for example, we want to add an item in here and we want to render this item over the, let's say the heart items and over the normal NPCs, you'd have to go back every time and check which order n layer is the MPC and the player and the background and so on. So in order to change that, in order to have a more dynamic way of choosing the layers, we can create sorting layers. So let's go ahead and create our first sorting layer. To do that, we can go up in here into the layers and click on Edit layers. So as you can see in here, we have the tags, we have the sorting layers, and we have the layers. Now the layers and tags will keep for later on. For now let's just focus on the sorting layers. And this is where we choose which Sprite or image assaulted in front of the other. Now if you look back into our walk vanilla, that's changed this and call this the monster or player, player demon or let's just keep it as player. You can see that the sorting layer that his own is the default one. And that's because we only have a default layer. Now let's go ahead and add a new layer by clicking the little plus in here. And let's call this the background. So now we can go into the background image and we can choose the sorting layer to be the background. So as you can see immediately, the sorting layer, which is the background, is rendered in front of the player. And that's because the field look back at the layers in here. You can see that the layer is in front of the default and you need to make sure that these are sorted correctly and are in a certain order. Okay, great, So make sure that the background is in front of here. Now we are going to create a layer for the player, but it's going to be your challenge. Your challenge is going to be to create the sorting layer. So create a new sorting layer called the player. Assign our player to the player layer and make sure that the player is shown in front of our background. So make sure that the order and the sorting layers is correct. So pause the video right now and go do the challenge. Oh, hey, welcome back. How did you get on with that? I hope you tried. It's very easy. We simply click on the plus end here. We create a layer called the player. Then we go back to our player. And in here instead of default, we simply choose the player and we can even set the order in there to 0. It doesn't matter. So now the player is on the player sorting layer. The background is on the background sorting layer. So even if we change the order and layer 2, let's say 600, even though the player is on the order layer 0 here, still rendered in front of the background image. So I hope you enjoyed. And before we move on, we forgot to do something or actually we didn't do it in the previous video. And that is creating a repository. Now, I didn't, I didn't want to create a repository. And the first video because I thought that maybe some of you would want to create their own sprites and then create a new project. So the way we create a repository, we've already covered this. We click on the Browse, we look for our projects, we see the legend of conquest. We select this folder and we're going to create, make sure that it's a good We are going to create the positive. Yes. And there we go. We need to make sure that we forget the library or ignore. I mean, so ignore everything beneath library. We create. This is our ignore file. So let's go and get the ignore five lists. So n here, go to the masters. There we go. We can choose to go Roll, Control a to select everything. Back in here. Where is it the dot gitignore based everything. Save that exit. And now let's see. Yep, everything seems to be good. Stage all. We are going to commit our work and usually, as we've said, recovers the initial commit. And this is the very exciting part. So now, and our commits, where are our commits? There? There we are, we are, we've created our first commitment and we've actually started our projects. So now we are really committed. There's no going back my friends. Let's continue on.
10. Colliders & RigidBody: Welcome back, My favorite game developers. In this video, we are going to be learning how we can add physics into our game and no longer have just images and sprites. We actually have bodies and physics in our game. So we've added a collider. We also learned what a collider is. We've added a rigid body. We also learned what that is and we learn something new and a new resource for information, which is the Unity documentation. So let's not waste any more time and let's get started. Oh, kay, so colliders and rich bodies, these are very essential parts and components of unity. So why do we actually need to add those two weird things? Well, because currently, although we have a player and he looks cool and we have a ground to stand on. And we have different Walters and so on and so forth. But these are just images, these are just sprites. So the player is just a sprite, the background image is just a sprite and we cannot interact with it with anything, nor can we move around. So let's start by understanding what colliders are. So what is a collider? A collider makes it possible for objects to interact and collide with one another. And we'll use it to make our player hit objects and interact with other physical objects that also have colliders on them. Now, what is a rigid body? A rigid body does something or a component in Unity that allows us to control an object's position through physics simulation. Rigid body object would be pulled downwards by gravity without adding any coat. And finally, we can also apply our own forces on them or on the rigid bodies. So now that we have a little bit of an understanding of what those are, let me just show you another very cool thing that you need to be aware of, and that is the Unity documentation. Now, you can see in here, I just typed in Google rigid body 2D in Unity. And you can see the link in here. It's the docs dot unity. And you can see what the rigid body is. Now you don't need to read every single word in here, but I do recommend that you at least skim over a couple of things in here. For example, the physics re-cast the on collision enter. Those are things that are good to know that they at least exists and you can use that. I never remember anything. I usually just love to know that there is something useful in rigid body 2D that I can use later on. And we also have a page in here for the collider study. And you can see that we have a circle collider, a box collider, polygon edge, capsule, and so on and so forth. So back in Unity, Let's go ahead and add a collider to our player. So we'll go into the player, will add a component and it's going to be a collider 2D. You can choose which collider you want. I think a circular collider will fit very nicely into here. So as you can see, there is a green line. It's a bit thin, but if I tried to change it, you can see that there is a green line and this is what the player can interact with. So we're going to make it a little bit smaller so it fits just around the player. And you can edit the collider in here by tapping this button. We can also change the radius and change the offset. So I'm going to move it just a little bit up and maybe just tried to make it as big as it should be. Never make it more than it should be. So just about the size, I think is good enough. And here we have the trigger and used by a factor. We will see what all of those are later on, but great. Now you saw how we add a component. I clicked in here on the Add Component button, I chose a circular collider. I could have chosen anything else. And you need to choose a collider based on the shape of your player or character and the world. Now, the next thing we want to do is we need to add a rigid body. So this is going to be part of your challenge. Your challenge is going to be to give, are there physics? So go into the player game object, check in the inspector, add a rigid body component and make sure that it is to D, because we have two types of rigid bodies. We have normal rigid body for the 3D, and we have a specific rigid body just for the 2D. And if you want, you can also run the code and see what happens. So pause the video right now and go do the shell. Kay, welcome back. So in here we are going to go into the player game object. We're going to check the inspector. Okay, very nice. And we are going to go ahead and add another component and it's going to be a rigid body and is going to be a rigid body 2D. So now we have a rigid body in here. And you can see that it has mass, it has linear drag, it has angular drug. We won't worry about that for now. But what we will be worrying about this, the gravity that is added, because as I've told you, we have automatic gravity on our rigid body. So when we hit Play, and now you can see it's had our little daemon starts falling and that's because the forces of gravity are acting on him. So what can we do about that? Well, if you had tried to read the rigid body 2D, you can see here that we have three types of rigid bodies. We have the dynamic, the kinematic, and the stack. And you can feel free to go ahead and read about all of those. What you need to understand is that kinematic and dynamic is whenever gravity acts or outside forces act on our body. Kinematic is when only the forces that we give it, our acting on the body and static, that means no forces can act on the player. So if we hit the kinematic, now we run the code. And you can see that our player no longer falls down so well that none, I hope you enjoy it. We need to make sure that we commit our changes. So here are a couple of changes. Stage all commit. Added a collider and a rigid body to my player. Commit the changes, and I'll see you in the next one.
11. Scripts & Variables 101: Welcome back, my fellow game developers. In this video, we've created a player script and added it to the player game object. We also learned about variables. We've added a bit of code and as you can see, we have this serialized field. Very scary. No, I'm just kidding. It's very easy. So I need your full concentration. Let's not waste any more time and get start. O k. So now it's time to start actually controlling our objects in the world. And the first thing we want to do is we want to use the rigid body that we just applied in order to start moving our little demon player around. And I think we are going to call this Jimmy, so Jimmy the demon. So first thing we're going to do is we're going to create a script and added to our daemon right here. So inside of our assets, we are going to right-click and go ahead and create a C-sharp script. And we're going to call this the player. All you can call this the player controller, player manager. I think player, just to sum up, everything is a good name. So make sure that you call it correctly using the player, hit Enter. Wait a bit just for the script in here to compile. And you'll notice that whenever it does this little thing right here, now we can use it. Make sure to wait for this to happen because I get a lot of questions while not working. Why you have you taught us something wrong? No, you need to just wait a little bit. Have patients. Now next thing we need to do is we need to add the script, the player. So we'll simply drag it over and to the player game object. And you'll see right here in the inspector that we have it in here. Oh, gave very nice. Next thing, let's go ahead and open it up and Visual Studio. So to open the script up, simply double-click on the player right here. And Visual Studio should open up. Oh, okay, correct. Now, don't worry about all of this we will go over later on how Start works, how Update works, and all of these right here, and mono behavior and the class player and the public. But for now, Let's focus on making our player moves. For that, we'll need the rigid body. And for that in order to access the rigid body will need a reference to it. So how do we get a reference to the rigid body? Well, we need to create a variable of type rigid body. And you might be asking, well, what are variables? Very nice question. Let me explain. Variables are just like boxes. So let's say we have a box that is called the lives. And what we do is we put a three inside of this box. So now we have a variable of type integer because it has an integer inside of it, and it's called lives. So a variable has a couple of things that you need to always know. So this is how we write a variable in coat or how we translate this box to code and our Visual Studio. So first of all, we have the accessibility. Who can access this? We have a public or a private and something I will teach you in just a bit, which is called serialized field. So who can access this as a public variable? Everyone can get in. Is it a private variable? Only the script we're using it on can use. Then we have the type, as I've said, it's an integer. We have other types we'll see later on such as strings, float, and so on. So a string is a string of numbers. We'll see later on what different types we have. We have the name of the variable, and finally, we have the data that is stored inside of this variable. So we have different types of variables. So for example, let's say lives can be three. So we have three lives, but velocity, for example, can sometime be 4.8 or 10.6. So in order to represent velocity and other things such as temperature, we need to use a float, where we can use a floating point to represent 4 a. Then we have the Boolean. And Boolean can be either true or false. So for example, our player, we can create a variable which is called is dead. So is our player that can be three or 4.8. It has to be either true or it has to be false. So true and false are the two data that we can put into the Boolean. Booleans are very important, as you'll see as we move through our project. Then we have the string. So a string is a string of characters. So the character M, I, C, H, E, L. So this is a string of characters that represent, for example, mining, which is Michael or Michelle. You can call me whichever one you prefer. And this is a string of characters. Put together in order to represent the variable. Okay, so with that done, the next thing we're going to do is we'll create a variable that is of type rigid body in order to get a reference to it. So in here we'll create a public. So public as you can see, the IDE already helps us a lot. Public. Rigid body 2D, and we'll call this deep player rigid body 2D. And another thing that we always need to keep in mind is the way we name our variables. As you can see, the first word wasn't capitalized. The second word is capitalized. And also sequent words that you have inside of the name of your variable are capitalized. And I'll show you why in here. And we can actually remove the 2D. We don't need that. And here, save that back in our unity. We can look to the right and you can see that we have in here a rigid body variable and a reference to it. So now we can add this rigid body, simply drag it over into this empty slot. And now we have referenced the players rigid body and now we can use it in our script. And as I've said, every time we capitalize a word, you can see that we add a small space in here for the name. For example, if I make this a small b, save that back in Unity, rigid body should be connected. And there you go, it is. So that's why we've added the B. And you can press Control zed, and we can go back and undo our changes. So very nice now that you've learned about variables and how we can create them that just put this back here. And now it's time for a small challenge. And your challenge is going to be to create a private variable or not create maybe changed to I private variable. So changed variable from public to private. Go back in Unity and check for the variable in the inspector. Pause the video right now, change the variable from public to private and see if it's still there in the Inspector. Oh, welcome back. So in here we are going to change this to a private. Make sure to always save your script and you know that your script isn't saved. If you can see the small asterisked as strict of their control S, save our script back in Unity. And now we can see that we no longer have the variable in here. So now how can we reference our rigid body? Well, we can use something called a serialized field. And let me show you what a serialized field is. And I'll also explain why sometimes we need to use public, private and a supervised field. So what's the difference? So a private variable is not available from other classes. It's not visible in the inspector. So why do we sometimes need a private variable? Let's say for example, we have the speed of our player and we don't want to, for example, be able to access the speed of our player by accident from, let's say, the shield item. So we make it private. So it can only be accessed from the player script. So the velocity which is private or the speed of the player is private. And it can only be accessed from the player script, not from the shield, the script, for example. So this is the power of using private variables. Now, public valuables are available from other classes, are visible in the Inspector and they of course not visible in the Inspector. You can actually see them plus column I think is useless. But anyways, and the serialized field, the joints both forces the public and the private, because serialized fields are not available from other classes, but you can still see them in the inspector. And this is a very, very helpful tool in Unity. So let's go ahead and make our rigid body a serialized field. So instead of private, we are going to make it a serialized field and make sure to always add these two brackets around them. So we save our script. We go back into Unity, and now we have the option to add the rigid body and you can see that it is already there. So we'll save that. And in the next video we'll start using our rigid body in order to move our player. As always, don't forget to commit our changes. I will stop doing this, but I will always do with, at the end of every single video because it takes a little bit of time anyways. Well that not, I hope you enjoy it and I'll see you in the next one.
12. Inputs & RigidBody Velocity: Welcome back, my fellow game developers. In this video, we are actually going to learn about inputs and we'll use our rigid body for something useful. So now our Jimmy, the demon, doesn't just stand there. He can actually move up, move left, move down, move right. And he can actually move not just horizontally and vertically, he can also move around. So let's not waste any more time and let's start using our demon o k. So let's first of all open up our script and let's explain a couple of things in here. So first of all, we have these three lines in here that starts with using, and this is a collection of libraries. So for example, when we write using Unity engine, that means we access a huge, huge code that allows us to use, for example, the start, the update, the mono behavior and so on. And this is the same for the system collections and system collections. Generic, they are huge libraries. And instead of writing all the code for, for example, for the start and so on, we simply add the using in here and we can use any code that we want. We will see a lot more of this later on where we will be adding our own libraries and using different ones up here. Now, the next thing, we have a public class player. So just like we have the variables that can be public or private, we can also have classes, and these classes can have inside of them methods and variables. You can think of it as a collection of small codes inside of the class. Then we have the name of the class which is player. And under no circumstances do you change the name and here, because if you change the name here, but you don't change the name of the script in here. You will have a huge error and it's very difficult to change later on. Next thing we have this, these two little points in here and mono behavior. And I'm not going to talk a lot about how inheritance works. But this means that player inherence from mono behavior and moral behavior is a base class. And what is a base class? It's where we have the start and the update. So basically, when we type this in here, that means that we can attach the player to a certain game object and we can use the start and the Update. Now, what our start and update, we have a comment in here. So the comment is always preceded by those two forward slashes. And start is called before the first frame update. So whenever we start our game, whenever the object player starts, the start method actually executes and we can add a lot of things in here that we want to execute whenever the player game object appears or starts or whatever or comes to life. Then we have the update and update called once per frame. So I think because you are trying to create games, you are familiar with frames per second. Well, update is called every single frame per second. This is where we can actually move our player and do various things. Check around the environment, see what happens and how the player interacts with the world. So if you want start as for initialization and update is for a movement and doing certain things. So let's start applying all of that. And we're going to be applying first of all, the movement of our players. So we have our rigid body. Now, what we want to do is we actually want to start moving. So what we can do is we can use the player body dot velocity. And you can see in here, if we just hover over it, a rigid body, 2D dot velocity, linear velocity of the rigid body in units per seconds. So as you can see, it's of type vector 2. And we all know what a vector is. Vector is just a component in mathematics that allows you to use the x axis and the y and deserved. But because we are using vector 2, that means we are only using the x and y. That's because we are in 2D, doesn't matter if we use the set or not. Anyways, back in our code. So velocity, I always like to use the ID suggestions and new vector two. And we're just going to give it a one by one. So this code right here will be called every single frame. So the velocity of the players rigid body will come the new vector 2, 1 f, 1, f, which are the coordinates. So he should start moving in the upper right direction when we start our game. So let's save the script. Let's hit back into our game and let's test this out. So when we hit play, you will see, There we go. So our little Jimmy daemon starts moving upwards and you can see that it happens every single frame. And we can also test the start later on. Okay, great. Now we have a bit of movement. The next thing we want to do is we actually want to use movement only when we inputted from our Keats before we dive in. I just want to make something clear about the scores. I'm not here to show you how everything is done. I'm here to teach you how it's done. So my goal is not to just for you to sit around and watch me type some code. My goal is to make you a master problem solve. And the way we do that is by starting to think like a game developer. So let's say, for example, I stumbled upon this problem. I want to have inputs for my gain. So what do I do? Well, I go into Google and let's say how to input in Unity. Okay, so we can see in here that we have something called an input manager. So let's go into the inputs. So we look in here, okay, and put very nice. We have get access, very nice. We can scroll down and Whoa, we have the static properties. So we scroll down, we read a bit, and then we see in here the static methods. And we can see that it returns the value of the virtual axis and this returns the value as name, no smoothing. Okay, Nice. So I think that the GET axis rho is something that we can use. Now of course, the process when you do it much longer, but I'm just showing you how we solve problems as we progress through our journey. And then here we go, the input dot, get access. Rob, How convenient. Now, let's say I have no idea how to use this. I can see the description. I can read how the value changes, and I can also see that we use it inside of update. How convenient? So here you can see that it's of type float. We give it a speed, we get an input and we multiply it by Time.deltaTime, which we will explain later on. And then we can actually add it somewhere. Very nice, so great. But what does this horizontal mean right here? Well, how convenient we actually have the Edit Settings input window. Okay, let's try this. So in unity, we go into the edit, we go into the project settings. And where is our input? Input Manager? We click on the axis and whoa, look how many axis we have. So maybe I am sounding a bit cheesy, but this is really how sometimes we figure things out as we are creating games and doing projects. So great. We have the horizontal, we click on it, we see that its name is horizontal and the negative button is the left, the positive button as the right. Very nice. Let's go ahead and implemented in our code. So back in here, we'll hit an Enter. And as they've told us to recreate a float, we'll call it the horizontals movement. And it's going to be equal to input dot, get access row. And in here they told us that we need to add horizontal and very important tip. And this will save you many, many hours. Trust me, whenever you have a string reference, that means whenever we have something that we need to put between two quotations, like in here, for example, this is a string reference if you type horizontal incorrectly in here, this code will not work. And not only that, you will not get an error. So whenever you have a string reference, it's always better to actually copy it and then paste it in here. Okay, great. Now we have the input using the get access row on the horizontal. And we are putting it inside of a variable of type float called horizontal movement. And now we can set this to 0. And instead of giving it some arbitrary number 1 f, we can actually give it the horizontal movement. We'll save that. We'll go back into Unity. And let me just dark this right here next to the, the inspector. We hit Play. And now if we click the a or the D, you can see that our player starts moving. But if we try to hit, we can use also the a and D, or the left and the right, the arrows. But if we try to hit the up and down, we don't have any movement. And if we try to hit the W and S, we also have no movement. So it's time to apply the vertical velocity. And I don't feel like doing it. So I'm going to give it to you as a challenge. So get vertical input and a plot. So get the input for the vertical movement. Apply it to the rigid body velocity and test it out in your game. So pause the video right now and go do teach challenge. Okay, welcome back. So let me just look at our project settings again. Make it a little bit bigger. So what do we want? We want the vertical. So I'll open up the vertical, okay, So negative button down, up as W and it's called vertical. So we'll copy vertical. We can close this. We'll go back in here. We will duplicate this line and the way we duplicate it will simply put the cursor at the end and hit Control D. So now we change this from horizontal to vertical and we paste the word vertical and here. So as a rule of thump, always remember, whenever you have a string reference, you always go and copy it. And now we add the vertical movement to the vector 2. So now what are we doing in here? We are taking the horizontal movement. We are taking the vertical movement. Then we are taking the velocity of our player rigid body. And we are setting it as a new vector to that is created from the horizontal movement and the vertical movement. Okay, great. With that done, let's make sure that we save the script back in Unity. We hit Play and now we should be able to move left, right, and up, down. Oh, grew rate. How cool is that? Our game starting to come alive. So I hope you gave it your best and make sure to commit our changes, as you can see, committed the last change where I created a player script and added a reference to rigid body. So I'll see you in the next one where we will begin to animate our player and make him a little bit faster. So I'll see you there.
13. Animator & Animation: Welcome back, My favorite game developers. In this video, we are going to start animating our Jimmy Dean. So when we had played, I mean, we don't need to hit play. We actually go to the animations. We can be walking to the left, we can be walking to the right. We can walk down. And of course, we can be walking up. So let's not waste any more time and let's start learning about animations in unity. Okay, So animations and animators in Unity, very fun. And let's start off first of all, by understanding animations. First of all, we have something called the animator controller. And this allows us, or allows you to arrange and maintain a set of animation clips. And you'll see how that looks inside of Unity in just a bit. Next, we have the animator component, and it's used to assign animations to a game object in your scene. So if your game object has an animator, unity knows that this can be animated. Next we have an animation. And what is an animation? It's several sprites are rendered one after the other, and it looks as a video. So what is a video when you watch a video or a movie, a series, or several images right next to each other that move or go from one to the other end you feel or do you have the illusion as if they are all continuous? And finally, we have the sprite renderer. We've already talked about it, but I'll just end here to remind you again that it renders a sprite fall to the graphics. So let's go ahead and create our first animation. So back in Unity in here, how are we going to do this? Well, we are going to use our continuous sprites of the Jimmy demon moving right, left, up and down. So if we double-click on the sprite, you can see that we have a movement forward, a movement upward or up, down, whatever you want to call it, then right and left. So let's start creating. First of all, we'll go into the player, will click on the window appear, will go down and click on animation. So now we have the animation and here we'll dock it next to the game. And make sure the true click on the player. In here you can see to begin animating player create an animator and animation clip. So in the inspector, I'll just make these a little bit smaller and we'll click on Create. So where this gives us the option of where we want to save these animations. So I think in assets, in the legends of conquest and assets, I'll just right-click in here, create a new folder. We'll call this the animations. We'll double-click in here. We'll create a folder for the player. And inside of this folder will create the walking right, or to the right or whatever you want to call your animation. So we'll hit save. And there you go. We have a timeline in here. We have the play, we have the record, and we need to make sure in here that we are working on the walking right? Animation. So how are we going to take this price of the walking, right? Which are these, and put him, put them in here. Very simple. We simply click on the first one. We hold down shift, click on the last one, and we drag it in here to the timeline. So as you can see right now when we hit play, they are extremely fast. So we can actually separate them apart. So we can put them ten frames apart from each other. So now when we hit run, you can see that we sort of walk. You notice that there is definitely something wrong, not working correctly. Why is that? Well, because if we just stop this for a second, we start with the first frame. We walk the right leg, then we stand straight, then we walk the left one, and then immediately we start back again in here. So what we want is to try and smooth this process up. So we are going to choose the first frame. We are going to copy it. And then we'll move ten frames to the right because as we know in here, are separated by ten frames. A piece based in here. Let's play. And there you go. You can see that we have a sort of a normal animation working for us. And if you want, you can tweak it. Let's say maybe separate them a bit more. So now when we walk, right? I think this but to yeah, I think this is a good speed. You need to choose your own speed and see how you want your player to look like while his, his walking. Okay, great. So now we have the right walking. Let's go ahead and create the down walking. So we'll create a new animation in here. So the way I did that, I submit to first create a new clip in here when we click new clip, and we're going to call this the walk down. So walking down, save that. Now we have a brand new animation. And if you want to, this mini challenge of creating this animation, you'll actually have a challenge later on. So let me just talk you through again. We go to the sprites. We choose our sprites. So this is the walking down, as you can see, we move them in here. We'll separate them. Let's say by 10. Again, we will take the last frame, we will copy it. So Control C, we will go to the frame where we want to put it, which is on the 50, and we'll paste it in here. And I don't think these are correct. So 10 then on the 2030 and this one is on 40. So when we hit play, we can see that our demon is working correctly the way we want it to. Okay, right? So we'll stop this right now. Finally, we have the walking up and the walking left. So this will be your challenge. Your challenge is to finish the animations. So first of all, create two more animations, 140 player walking left, and one for the player walking up. I'm not sure why are these underscores? You can name your animations whatever you want. It depends on you. Maybe when I created this challenge, are you thinking calling them this way? No worries about it. You call them whatever you want. So pause the video right now and go do the challenge. O K. Welcome back. So I hope you tried to do your best. One thing we didn't mention is the animator right here on the player. So as you can see, we have an animator in the inspector of the player, and we'll see later on the animator controller, you can already see it right here. If we double-click on the player, This is the animator controller, but we'll worry about that in the next or the upcoming videos. Now let's finish our new clips. So we'll create a walking up. So walking up and we are going to go into where's our assets, whereas walking up. So these are our sprites, hold down Shift settlement here and make them wide apart. Copy the first one. Put it on the last one, hit Play. Yep. Good enough. And then we'll create a new clip and we're going to create left, hit Save. And whereas our walking left, we will choose these four, put them in here, separate them by 30, will copy the first one, put it as the last one. And now when we hit play, we are walking left. So now we have the walking down. Our monster walks down. Let me just zoom out a bit and maybe go to the game. And nope, that who not work, we need to choose the player. And maybe if we put it up here. So now when we walk right at play, so we are walking right? We had the walking up with play. We are walking up. We are walking down, and we are walking left. Okay, Excellent. So with that done, I hope you enjoy it. I hope you created your own animations. I think that our sprites will need a bit of tweaking when we start adding everything up, but no worries. And the next video we are going to be using these animations in our animator controller or the state machine, however you want to call it. And we'll be setting them or starting these different states from our code so that none, I hope you enjoy it and I'll see you in the next one. Don't forget to complete your work.
14. Transition & Blending: Welcome back, my fellow game developers. In this video, we are going to be learning all about transitions and the blend trees and y in this case and our particular case, we want to be using a blend trees instead of transitions. So when we hit play, you can see that we have all this cool stuff right here happening. And if we move the cursor to the left or Jimmy daemon will start moving to the left, down. He moves down, up and moves up, writing moves right? And not only that, the video is a bit long because we actually tried to tweak around and enhance the way we sliced up our sprites. So let's not waste any more time. This is a very long video and let's get started. Oh, so first thing that we need to do is we actually need to create animations for the either positions. So that's when the player is actually standing and not walking. So in order to do that, we're going to create a new clip. It's going to be either link down. We save that, and we're simply going to drag, where is it? One frame? So this is a one frame animation. When we play, nothing changes. It just place this one frame and this will be important later on. You'll see how. So again, we'll create the idle up, save that. Vary, go, play. Okay, great. Create New. And there you go. The EIDL, a left. Great. So now we have the idling and we walking. Next thing we're going to do is we're going to create transitions between everything. So let's go ahead into our animator. If you don't have your animator, you can double-click in here on the inspector of the player. Or you can go to Windows animation, the animator I've talked at right here next to the scene. So as you can see right now we have all the animations right here. Walking right, walking down, walking up, walking left, idling down. And what else do we have? The idling up the island, right, and the idling left. So this is a bit too small. Just undock it somewhere in here and open up the screen completely so we can zoom in and have fun. So what are we actually going to do in here? Let me just do this like this, because when we click on one of these animations, we want to see the inspector. So what are we going to do? First of all, we have the entry and we have the default animation. So currently it's the walk, right? We want to change that. Let's say for example, the normal animations that we want or the default animation that we want is the idling, right? So we are going to right-click on the idling right, and set this as the default state. So as soon as we enter, we are idling, right? Okay, great. Now how are we going to transition to actually walking, right? Well, we can put the animation in here. We can go ahead and right-click Make and transition and put it into the walking, right? And as you can see, first of all, we have a transition to walk in right from the idling, right? And if we click on the transition that is represented in here, you can see that we have exit time. We can turn this off. We can have transition duration. So how long it takes to go from one animation to the next, the exit time. So after finishing the animation or after a certain time of finishing the animation, we can exit from it, and so on and so forth. There are many things that we can have in here, and we can also add a condition to transition from the idling right to the walking right? And how can we do that? Well, we can do that for example, let's say we go to the parameter. We can create a parameter. It can be either a float integer Boolean or it can be a trigger. So we can create a, for example, let's say we want to start walking after our layer moves at a certain speed. So we create a float. We call it, let's say for example, movement y. So it's the movement on the y-axis. And now if we go to the transition, we add a plus. And here you can see that automatically we have movement y and we can set the greater. So for example, if the movement y is greater than, let's say two or three or whatever, we transition from simply idling, too, walking. And this is how we usually set up animations. But you can see that this can be very cumbersome. Why? Because let's say for example, we are walking right? And then we want to immediately start walking left. Well, we'll create a transition. You tell me. Okay, great. But let's say, for example, walking right? Suddenly we start walking up, okay, then make a transition to walking up. But then a transition from walking up to walking left. A transition from walking up to walking right? And you can see that this becomes very cumbersome and we still didn't figure out how we are going to be adding the idling. So this is where we are going to use something a bit different and it's a bit advanced. But this is what we will need in order to actually use all of our animations and state. And it's called the blend tree. Let me show you a unit, dogs what blanches are. You can go ahead and skim through them, see how they are created. This is very nice, they are very documented and I do recommend you go and read about all of these are going to be using all of them. And what I want you to focus on is in here, and we've talked about transitions. And you can see that transitions are used for transitioning smoothly from one animation state to another over a given amount of time or certain condition. But the blend trees are used for allowing multiple animations to be blended smoothly by incorporating them part of varying degrees. So as you can see, because we are looking to incorporate multiple animations to be blended together. Using a blend trees is a much better way. So let's go ahead and create our blend trees. So back in Unity in here, we can actually see and the dogs right here, the way we create. So select, Create state or right-click in the empty space in the animator controller. And we are going to select create and from new lunch case. So back in Unity, let me just make this a little bit bigger. We've deleted all of our transitions, and now we're going to right-click. And we're going to go to Create state and from a new blend tree. So we're going to call this the walking blend. Now the walking that, the walking a bland. And let's just go ahead and delete all of these from here. And also delete the idling, right? And as you can see immediately, because there is no other animation over 90 walking blend, it's going to become the default layer. Okay, great, So now if we double-click on the walking blend, you can see that we are no longer on the base layer. We are on the walking a blend layer. And if we click right here, you can see that we have many things that we can change. And one of them will be the gland type. We are not working in 1D, we are going to be working in 2D, simple directional. So now we have the movement on the y and the movement on the Y. That's why we need to create a, another movement which is going to with the movement on the x. And now the parameters can be the movement x and the movement. Why? Next thing we're going to do is we'll make this a bit smaller and we are going to add motions to our plan. So first thing we're going to do is we're going to add a motion for walking up and walking, right. Or let's go ahead and add the motion for walking, right? So let me just make this a little bit. Let us search for, or we can click on this little circle right here. If we click it, we can go and search for the walking right. Double-click on that. So now we have this first motion and we are going to put it on a certain circle. So if we first of all cross 0, 1, we keep this at 0. And we go ahead and add a second motion. You'll see that we have a position in here and this red dot when it moves, it goes to one of the positions. Let me show you what that means by creating a second one, which is going to be the walking up. So we click in here. We are going to be walking up. And we're going to set the position here on the x to be 0 and the one to be 0.1. So as you can see, now, if we are moving towards one of these, the animation is going to change. And you will see how we are going to be manipulating movement x and movement. Why? In order to start changing these? Now you can see that we have this circle right here. Next thing we're going to do, and you can see this literally, I was trying to move my read button and there you go. If we need to move them between these two lines. Or you can see here simple directional then should have motion with direction less than 180 degrees apart. So if we move closer to this one, we move to the right, we move closer to this one, we start moving up, but that's not what we want. We want to also be able to move down and move up. So this is going to be part of your challenge. Your challenge is to finish the other positions. So create two more motions, one for walking right and 14, walking left. Make sure you set the position x and position y correctly. And finally, play around with the red circle and see how all of these emotions actually blend. Okay, welcome back. So we are going to add two more motions. One of them will be walking down and one of them will be walking left. And as you can see, these are blended into this tree and it's based on the movement. Anyways, let's continue on in here. So walking down, where should be the walking down? The walking down should be, I believe minus 0.10. Minus 0.1 should be here, and this shot should be 0. And then we have, where is it? It's the walking left on the position x. It should be minus 0.10. So great. So now before we move to the left, we are going to the left. You can see even the little blue here. It's kind of blue that we move to the right. So we are moving right, we are moving down. You can see it's getting a little bit bluer. And this is what we mean by blending. So we are blending the animations together using the movement x and the movement. Why? Correct. So now we can go ahead and drag this somewhere maybe on the scene. So now when we run our game, so we move right, you can see that he is moving right. When we move left, we are moving left. When we move down, we are walking down. And when we move up, we are well moving up. But as you can see, there is something not quite right, as if our demon is jumping from place to place and that's because of the sprites, the way we slice them up. So if we go back into our assets and let's go ahead and create a folder in here. We'll call it the scripts, and let's put the player script inside. And again, we'll create a new folder and we'll call this the sprites. Maybe we'll create sub-folders and side. So the sprites in here, if we click on the sprite editor, you can see the way they are sliced up. And that's not quite what we want. We want to always have our slices be, or our player to always be in the middle of our slices. So how are we going to do this? Okay, welcome back. So after a bit of tinkering and here, I finally decided how I'm going to make my demon. So if in your sprites or the ones that you've chosen from open game art or aligned correctly. Great, I'm very happy for you, for the ones that don't have it aligned correctly like me, the ones of you that are using the dragon. And here, here are a couple of rules that you need to follow in order to align all your sprites. First of all, you need to make sure that every single cut the demon is in the middle, or the character that you're using is ending middle of the slice. So you cannot just automatically slice everything. Just slice grid by size may be 64 by 64, and then you'll need to continue on by hand. So first of all, you'll notice that all these squares in here have the same width and the same height. So as you see, 64506450. So this is important for all the ones that are either facing forward or facing backwards depending on how you want. So the first two rows should be the same. But for the ones that are moving horizontally, there should be a different size because the demon is not aligned properly. But there is a very nifty way. So I chose to make it 45 by 45. So the width is 45 for all the cutouts. And 45 and height. I found that this is a very good number. So the next thing is how are we going to position them? We don't want to just wing it. So in here you can see the position of the cut-offs. Or if I move on the X, you can see that most. And on the y it does so also. So the 75 is arbitrary. I just tried to make him in the middle as much as I can. And then the position will just increase by 64, Y 64, well, because the width of the dragon and here is 64 and I think the sprite is dissected or put on for that reason. So you can see that this first one is at position 0, second one is at 64, 128, 192. But how about this one? So it's 1983, 174, and also all of them need to be on the same y. So this is important. Next thing, we have the dragon in here. So you can see it's at position 211 because we have put it to the right as much as we can, and then we simply remove 64 from it. So 147, 83, and 19. So great, but that done, let's go ahead and apply all of that. And you'll see that now our animations should be smoother without us actually changing the animation sprites on the player. Because whenever we make modifications to these sprites, they are changed all over our game. So now when we hit play, we go to the animator. You can see that by default he's immediately walking right? If we click on the Blend tree, we start moving him to the left. He starts walking to the left. You can see that it's very small. It's on the same height and you can feel he's moving in same place and not just jumping. And then down, and then up, left, down, left. And you can see it's very natural. Maybe it does need a bit of tweaking, but that's for you if you have a bit of OCD. So great with that done, I hope you enjoy it. Let's go ahead and commit our changes. And in the next video, we are going to using code to actually trigger these animations. So I'll see you in the next one.
15. Blend Trees Animations In Unity: Welcome back, My favorite game developers in this video, when we hit the Play button, we not only walk without player, but we can actually change the direction he is walking using the WASD keys, and it's based on the players velocity. But the problem is that we don't have an idling state in the blend. So we create a another blend tree just for the idling of our player. Now we won't be implementing it fully in this video, but we will in the next. Okay, so let's not waste any more time and let's get started. Oh, okay, so currently, when we run the game, you can see that our player is walking to the right, but even though we are moving up and down, there is no change in his animation. So what we want to do is we want to attach the movement x and movement y to the player animator. So let's get started. First off, let's go ahead and open up the player script in here. So whereas the player script double-click, and let's open up Visual Studio. So in here, the first thing we want to do in order to start controlling the movement x and y, we want to get a reference of the animator. So we are going to create a serialized field, and here it's going to be of type animator. So Annie May talk, and we're going to call it the player animator. Okay, so we remember to capitalize every word except the first one. Let's go back into Unity. That's wait for the script to compile. And let's go ahead and drag the animator from the inspector into the inspector and set it in here. Great, So now we have a reference to the animator. Let's open up the Animator window. And let's go ahead and open up the walking the plant. Now what do we want? We want the movement x and movement. Why? Because these are the ones or the variables that control the way our player is walking. So we're going to go ahead and use a function that is called the animator dot set float. And let me show you what that is. So if we go in here, you can see we've typed AnimatorSet float, and we're going to open it up and unity docs. So here you can see that we have the set float and we can see how we can declare it. So you can see that first thing we said the string name, and that's the name of the parameter that we want to change. You can see it right here. So what's the name, the name, the parameter name, and then the value which is the new parameter value. So how are we going to attach this? Well, and here we are going to pass the players velocity into the animator set float, and that will change the movement and movement. Why? Let me show you what I mean. So we're going to get the player animator. We're going to set the float. And because this is a string reference, of course we are going to get, go back in Unity, copy the movement acts. Open. Visual Studio, paste it in here. And what is going to be the value? Well, it's going to be the player rigid body dot velocity dot x. And then we are going to duplicate it. And as I've said, we duplicate this using Control D. And instead of movement x, this is going to be movement Y. And instead of velocity of x is going to be the velocity dot y. Okay, great. Now if we go back and unity, make sure we save all of this back in Unity. We had playing. So now if we start moving up, you can see that our demon Jimmy is moving up. And if we move left, he moves left, down, right, up, down. And you can see how the movement is changing right here in the enemy. So when we are walking through the left, you can see that the movement acts as minus1 while movement y is 0, we walk down movement and this minus one, and so on and so forth. So great, this is amazing. But the problem is that as you can see, when we let go of the keys, are demons still walks forward and we need to fix them. And how we fix that? Well, we are going to use the idle animations that we've created in order to set them at the end or when we stop actually moving. So to do that, I'm going to issue you a challenge. So set up the rest of idle states. So you'll need to create the three players idle animations for either player. I think we've already created all of those. You'll need to create a new blend. This is not something that we've created and call it the player idle bland, or whatever you think suits your needs. You'll need to create two parameters, the last x and the last y. And this will be the direction of which we last faced. And you'll need to set up the four idle directions just like we did in the walking. So pause the video right now. If you don't remember how we did all of this, you can watch the video previously or you can try and do your best shot, makes sure that you try your hand at this challenge. So pause the video right now and go do the itch. Okay, welcome back. So in the base layer, we are going to right-click in here, create state from new blend tree. We are going to call this the either blend. And that's because we've maybe the idling blend. So either link bland and this is just to stay congruent with the walking glands. So we have an idling gland, a walking gland. When we double-click on the idling blend, you can see that we have the movement x and y, but we don't want that. We need the last x and the last y. So we're going to create a float, the last, or we don't need to capitalize the last X and float the last. Why. We are going to make this a 2D simple direction and the parameters are going to be the last x and the last. Well, now we need to have four motions in here. So these are our four motions. We are going to add the idling, idling right arm up and the, Whereas the idling down there. So what is the idling left? What is the position of Aileen left? It's going to be minus 10. Then the widening right is going to be 10. Either in AP is going to be 0, 1, and I will link down 0 minus swap. Okay, great. So now when we look up, we have the little button. You can see that we can just check and make sure that it's working. So we move up. You can see that we are idling up. We are idling down. We are idling left and right. And I'm looking at the color right here, if you can notice it gets a little bit bluer whenever we are choosing the direction, and it's based on the last x and y. So I hope you did the challenge. I hope you enjoyed this video and you actually created your own land. It's very important that you always try to do these challenges. So with that said in the next video, we'll be implementing the idling states into our player. And I'll see you in the next video.
16. Facing The Right Direction: Welcome back, My favorite game developers. In this video, we've actually created a way to remember the last direction our player was facing. So now when we walk right, we stop. We remember that the less direction was right. We remember the last direction was left up and down. And this makes our game much more, let's say, realistic and butter looking. So let's not waste any more time and let's get started. Oh, okay, so now we want to create a way to transition from the walking to the idyllic. First thing we want to do is we want to make the idling the default layer. The way we do that, we've already covered this, we right-click and set as the default state previously when I saw the layer, I meant the default state. So upon entry, we can see here that we start idling. The next thing we want to do is we want to create a transition between the idling and the walking. In order to do that, we'll right-click, make a transition and set it into the walking black. Now, if we click on the transition right here, you can see that we have an exit time and we have transition duration and so on. So what we want to do, we don't want any extra time, as we've said, exit time, as a time where the walking turns back to idling, stops completely. We don't want that next, the transition duration, you can set it as a small little time, but I think 0 would be better when we test this, we'll see if that is better. Next thing we want to do is we want to see what is the condition to transition from the idling into the walking. So if we hit the plus and here we can see that we can set the movement x or the movement y, or the last x and y. Now we don't want to touch any of the last x and y. We simply want to transition based on the movement and movement. Why? So if the movement x is greater than 0 plus one, then we will transition from idling and to walking. Again, we want to check for a movement. Why? So if we make a transition from idling too, walking, again, you can see that we have multiple transitions represented by several arrows on the same line. We also want to uncheck the exit time. We want to set the transition duration to 0. And the second condition will be if the movement y is greater than 0.1, okay, great. You can change the transitions appear, you can see them. So it's the eye-opening to the walking. And these are our conditions, the movement x, the movement. Why? Now? A, another thing we want to check for is if the movement on the x is less than minus 0.1. So this is important to keep in mind because of the movement is less than minus 0.1. Then we will transition into the walking but to the other direction. So we'll uncheck the exit time and duration. And finally, this should be pretty obvious if we have the condition of the movement y being less than minus 0.1, then we also transitioned into the walking a bland, okay, so movement wireless then zero-point one, movement x less than, greater and greater. Now, before we move on, we also need to create a transition from the walking to the idling. And this will require only a single transition with multiple conditions. So we'll set the transition duration back to 0 and the exit time to 0. So we'll add a condition in here that whenever the movement on the x is greater than 0 or minus 0.1, then we want to transition back. And because we don't have, let's say, multiple ways of going back only need one transition. And we'll add all the conditions on it. So the movement x is less than 0.1. If the movement is greater than minus 0.1, and if the movement y is less than 0.1. Okay, great. So let's save that. And let's go ahead and test this out. So when we run our code, you'll see that our player is currently idling and you can see it in here on the idling bland. And if we start walking up, you see that we are in the walking bland. When we stopped, you can see that we are idling, but we are defaulting to the sprite where the demon is looking to the left. So again, we walked down, if you walking bland, walking left. And if we stop walking, you can see that we turn to the other side. And this is not something that we want. We want to actually make our player or Jamie Dimon, remember the less direction he was facing. And based on that, well, when we stop, go into the eye-blink blend face that way. But in order to do that, we will need something called an if condition. So let me explain what an if condition is. Conditional if-statements structure. So the way we write an if condition, it's simply what it means. If some condition that needs to be true, we need to put them inside of these two brackets right here. So if some condition that needs to be true is true, then the code inside of these two brackets is executed. So if we have a condition in here that is false, The Golden here is not executed. But what happens then? We only have this if right here, we just move on with our code. But we can also add an else if. So, let's save this condition right here is false. Then we move on to the else. If we have some other condition that is true or that needs to be true. And if that condition is true, then we execute the code inside of these two brackets. But if the condition right here is true, we execute this code and then we move on. But what if this condition is false and this condition is false? And if we have several other else-if with all of their conditions all false. Well, we can also add an else. In the case where all the conditions in the series right here are false, then the, this code which is inside of these brackets on the else is executed. So let's try to use this new acquired method and implemented into our code. So let's open up Visual Studio and here, and let's create a condition in here. So we'll say that if the horizontal movement is equal to one, then we are going to call the player animator. We are going to set the float. We are going to access the last X. And I think, well, you know what, let's not even try this. Let's go back in here. Let's copy the last X. And even though I am 100% sure when ever we are using string reference, always try to go and copy it. It's a good habit to have. And we'll set the horizontal movement. So what is happening in here? We are using the get access role. And if we remember when we looked at in unit thoughts, whenever we are using GET access row, we go from either one minus one or 0. So what we are seeing in here, if the horizontal movement is one, so we are walking to the right, then we will set the last x as the horizontal movement, which is equal to one. What happens in that case is if we go back in here and two are idling gland can see that if the relaxed x is 1, that means we are facing, right? That means we will remember the last x and set it as one. So this way our player will remember the direction he is facing. Okay, great. Let's go ahead and test this out and our gain. And when we run the code, so we're facing the left when we walk right, if we stop walking. Incorrect. So as you can see, we have remembered the last direction our player was facing. If we move up and stop moving, it's always to the right. Okay, great. Now the next obvious thing to do is to set all of the directions and that's going to be your challenge. So right, all the other conditions. So create a conditional statement for the other three directions. For the vertical movement should set the last why. And I'll give you a couple of hints. We have the horizontal movement should be minus1 and the vertical movement also should be checking for the minus and plus 11 more thing that I didn't explain, sorry. Whenever we are comparing two variables. So we are comparing horizontal movement to one. We use two equals signs, not just one. When we use a single equal sign, that means we are assigning the value here to the variable. But when we are using two equal signs, that means we are comparing them with that said, pause the video right now and go do the challenge. Okay, welcome back. So how did you get on with that? Now what we can do in here, we can create an else. If the horizontal movement is equal to minus1, then we will duplicate this and move it down. The way I move this is by holding Alt and pressing the arrow keys. So now if the horizontal movement is minus1, we will set the last x as the horizontal movement. Well, obviously minus 1. Now, let's save that and see if it works in our game because I want to show you a more efficient way of doing this. So we save. We walk right, we are walking right, we walk left. We are stuck on the left. When we walk up, we again go back to the left. Okay, great. So this seems to be working, but there is a small problem. We have duplicated code that isn't very nice and here we don't actually need it. So what we're going to do is we'll delete the statement. And instead, in here we'll create a second condition that checks if the horizontal movement is equal to one. Or using these two straight lines or the horizontal movement is equal to minus1, then we will set the last x as the horizontal movement. And if we save that, go back into Unity. We run. When we walk right, we are stuck at the right, we walk left, we are stuck on the left. So as you can see, this is, this was a very good demonstration of how sometimes different code can give you the same result. And finally, we need to set v. Vertical movement is equal to one. And the vertical movement is equal to minus one. But now, instead of the last x, we are going to set the last y. And instead of the horizontal, we are setting the vertical. So back in our game, we run the code. And now when we walk up, you can see the last y in here is one. When we stop, there you go. So our Jimmy demon is stopping when ever we are, or the Jimmy demon is remembering the last direction we were moving in, again, the left to the right. And as you can see, we have excellent movement and our game, which is very, very nice. Okay, great. What we'll do in the next video is when we walk towards water, you'll see that for some reason the demon is able to walk on water, which is something that we don't want. We want him to be able to stop at this exact place or at least stop whenever we had the cabbages right here. And we'll also have better control of the walking speed on our dean. So I'll see you in the next video.
17. Colliding With Objects: Welcome back, my fellow game developers. Remember when we were able to walk through any object? Well, as you can see, we can no longer do that in our gain. So the waters are unreachable and the cabbages are a solid object. So let's not waste any more time. There is a bit of tweaking that we can do in here and let's get started. Oh, okay, so the first thing we want to cover, or we want to do is actually making our player just a little bit faster. But not only that, we want to have the ability to control it. So what we want to do is to create a variable in here that we'll be able to change whenever we want. And then multiply that variable with the players velocity or movement. So let's open up our code. In here. We are going to create a variable which is going to be of course, a serialized field. Unless you want to be able to X, then you will make it public. And we're going to make it, of course, a float. Or you can make it an integer. The depends on you. We can make it an integer. Let's make it an integer because we haven't done that. And we call it the move speed. And let's just set this to one for now. So down here, after we set the players rigid body velocity to the new vector 2, we're simply going to be multiplying this by the move speed. We'll save that. Let's go back into Unity. And there you go. The move speed appears right here. So now if we hit play while we're moving at S1, if we increase it to 30. Now you can see that we are moving very fast. So let's make it a little bit slower. And if you remember, we've changed the player move speed to 30 during play, but now it's back to one. That's because everything that we changed during play time is reset back to the default value. So we'll need to change it in here to, let's say three. We run the code and there we go. He's a bit faster. Maybe make, let's say five. We run the code, run the game, and there you go. I think five as a good enough speed, we need to adjust the speed of the animation. Maybe if we make it, then let's see how that looks. Then as I go too fast, Let's make it maybe I think seven is a very good number. Okay, So seven it is. Okay, Great. Let's see if that the next thing we want to change is, as you can see, we can currently move through our cabbages, which is not good, and through the waters, which is also a very bad idea. So what we want to do is we want to add colliders to these objects around us. So if we look on the collider, on the player, there it is. And I think we'll make it just a little bit bigger just so it touches the feet. Okay, So save that. Now let's go ahead and add a collider to the waters. So we are going to right-click in here, create a empty game object. We'll call this the waters will reset its position. And the way our reset it, simply click on the three buttons or the three dots right here and hit reset, everything will turn to 0. We'll add a collider, and it's going to be a box collider 2D. Let's move it here. And let's change the size of the collider so it fits over the waters. There we go. Let's save that. Let's run the code. That's one of the games. So now when we walked to the waters, yep, nothing happens. And why is that? It's because we haven't added a rigid body. So we're going to add a Rigid Body 2D, hit Play, and now we should, okay, So we forgot to make it static. So we'll make this rigid body static. And now when we run the game, hopefully we will be able to know we are still not able to interact with. So back in our player, I finally figured out what the problem was. So on our player we made the body type kinematic. And this means that we cannot interact with or that other objects with colliders cannot affect the player. So what we did is we changed the policy type 2 dynamic and simply set the gravity scale to 0. Now we should have done that from the beginning, but I think this was a great opportunity for us to learn how everything works. So now when we hit play, we can see that we can no longer walk towards the water and you'll notice that something is not working properly. That's because, well, let me just try to show you this using the colliders, so we'll stop the game, will open up the waters collider also, so we can see everything. And you will notice that because we are a circle, you can see how the circle looks in here. That's why we can not cross this barrier. So when we walk the circle will move or glide. There. You can see it. The circle of the collider glides over the surface in here and we start spinning. So if we try to, now we can't even escape. So we can make this a bit faster, drag it down. And this is a big problem because we don't want Jimmy to be circling around the game would be really weird looking. So what we can do is we can actually add constraints to our rigid body. If you look on the player, these are the constraints. We can freeze the rotation around the z. And why is that? Well, because if you look at the transform moiety, which gives you the position and rotation when we start rotating, you can see that we are rotating around the z axis. And it's more obvious if we unclick the 2D, and you'll see right here that this, the Z axis, which is blue, you can see right here, is the z axis and we are rotating around it. So back to 2D mode will freeze the rotation on the z-axis. And now we can safely see that we are not rotating. Okay, great. So with that done, the next thing is to stop our player from hitting the cabbages. And that's going to be part of your challenge. Make the standards solid. So at a collider to the stands next to our player, make sure the player cannot walk through them. So this should be easy. Pause the video right now and go do the challenge. Oh, okay, welcome back. How did you get on with that? So this shouldn't be too hard. We are simply going to duplicate the waters. We are going to move it right here and we'll rename this to the stand. And let's go ahead and change the colliders. Oops, on the stance. So we're going to move. And here you can see clearly the green lines. So now you can, even if you want, make this just a little bit smaller on the sides. And that's because of the way our Daemon set up. So now if we hit play, we shouldn't be able to interact with the stand's. Yep, There you go. If you look on the player, see that the circle starts interacting. That's why we made the stance a little bit smaller on the sides. If we walk from up, yep, there you go. We cannot walk through them. And we can also add the colliders to the shack right here and to the potato sacks and so on and so forth. But in later videos, when we start creating our own tile sets and maps, you'll see a much smoother and better way of handling all of this. Well, that said, I hope you enjoy it and I'll see you in the next video. Before we go, we least, we shouldn't forget to save our repositories. So backend source tree in here. We are going to stage all of that. And we're going to name our commit added colliders to our objects in the world. Okay, great, we'll commit all of that. And we can look at the master branch and you can already see our project taking shape. And it's very nice when you have all of that in front of you with that said, I'll see you in the next one.
18. Section 3: Switching From Scene To Scene: Welcome back, My favorite game developers. In this video, we've created a second scene, and we also created an object called area exit, which allows us to exit from this area. But for now the only thing that it does is it simply makes sure that we are the player. So if we walk through, you can see the collider. And here, as soon as we walk into it, you can see that in the console we print out this is a player that entered. So let's not waste any more time and let's get started. Oh, okay. So first thing we need to do is we've actually changed the name of the scene to town, the one we are using currently. I also changed the players collider right here. So you can see that I just made the circle around the feet and the head. And I noticed that it makes the interactions with the waters and stands butter. Okay with that out of the way, let's go into the file and let's create a new scene. Make sure that it's 2D. Hit Create, and we are on a new scene. To save the scene will simply press Control inside of scenes and let's call it the mountains. Click Save. Next thing we want to do is we want to add a background to the scene. So let's go into our background images that I've provided. You. Click on sprites, and let's drag the image in here and to the sprites. And now we'll drag it into our scene. And as you can see, it's a bit small. So we'll make the pixels per unit. I think 64 hit Apply. There we go. So now we have our beautiful scene with a couple of mountains and this stone man right here. Let's set safe. Okay, great. The next thing we want to do is we want to go back to our previous scene and the town. And here we are going to create an object. So we'll right-click create empty game object. And this will be called the area exit. We are going to reset its position. We are going to add a component which is going to be a collider 2D. And this collider 2D is triggered. And what we want to do is to set it right here on the edge. And we'll make it as big as the road as so. Let's make it just a little bit bigger. There we go. Now we have the area exit. Now the next thing we want to do is we want to create code that allows us to actually trigger this area exit. So whenever we enter this area right here, we want to make something happen. And the way we do that is using something called the On Trigger Enter. So if we go into the documentations and unity, you can see that we can use something called the On Trigger Enter. And the description right here reads, when a game object collides with another game object, Unity calls the On Trigger Enter method. And you can see in here how it's used private inside of the class on Trigger Enter, it gives us an argument. We will learn more about arguments later on. But for now, all you need to know is that this is triggered whenever a game object interacts with the collider and whatever the game object is, its collider a scent through this other argument right here, which is inside of these two brackets or mature how these are called. Anyways, let's go to Unity, and in here we are going to create a script. So back in our scripts, we'll right-click in here and we're going to create a C-sharp script. We'll call this the area exit. Hit Enter. And there you go. Now we have the script. We'll wait just a little bit for it to compile. And now we can add it to the area exit game object will double-click and open up the script. So what should we be doing in here? Well, the first thing we want to do is we go ahead and create an on Trigger Enter to D. And you can see right here we had entered. And you can see that the description entrepreneur enter scald when the collider 2D others, or right here the collision enters the trigger. So collision other, you can name it whatever you want. You can even name it Michael if you want. But we'll keep it as collision as the default that is provided to us. Okay, Great. Now the next thing we want to do is we want to make sure that it's deep layer that enters the area. We don't want to trigger this whenever, for example, an object or an item or some weird MPC. Enters, we don't want that because we are going to be using this in order to transition to the next area, to the mountain area that we just created. So how are we going to be able to identify the player? Well, we can use something called tags. So in here you can see we have a tag on the area exit. We have a tack on the stands, and we have a tag on every single game object. And you can see the tag on the main camera is the main camera, and this allows us to identify this camera as a main camera. We can also do this with the player. So on the player, you can see the tags right here. You can click and you can see that we already have a player tag default in Unity, we can also create our own tags. So if you remember previously when we created our sort layers, we had the layers in here and we had the tags also. But because we already have a tag called, the player will just use it right here. We'll save that. Now in here, when we enter, first thing we want to do is we want to check if the GameObject that entered the area exit is actually called the player. That is a challenge for you. So you'll need to check for a player. First, create an if condition inside of the On Trigger Enter. Then in this condition, check for the tag of the collision, which is the argument that is sent through, and then make sure that the tag is that of the two layer. So how can you do this? I'll give you a small hint, but if you are feeling brave enough, pause the video right now and go research how you can check for a tag. If not, I will give you the hint right now. Last chance. And you'll need to use a method called compare tack. So pause the video right now and go do the challenge. Oh, hey, welcome back. So I hope you didn't want to use the hint. I hope you went out of your way and actually research how you can compare tax or check for tax. If not, I hope you actually use the unity of dogs in order to search for compared tag to know how it's used. So in here you can see public boolean. That means this returns a Boolean. That means if it's true or false. And inside of here you can pass the string or the tags string that you want to compare to. And conveniently enough, they actually use the other dot game object which is on the Trigger Enter. It's called others in here, not collision. And it uses gameObject.com tag and also checks for the player tag. How convenient is that? So I really didn't set this up. I don't know how this could have coincided like this. Anyways, in here, we are going to check for the player. So we'll create an if condition will open up the brackets and we'll call the collision dot. We are going to check for compare tag, open up the brackets. And in here we want to call the player. But of course this is a string reference, so we'll go and actually we have to copy this one. So Control C, go in here, control V, and let's remove it. We can't actually copy the tag immediately, which is the player. So we'll settle for what we have, but we need to make sure. So player yep, it's the same. And in here, just for the sake of testing, we are going to go ahead and debug dot log. And we're going to print, this. Is a player that entered. Close this off and back in Unity. Let's wait for this to compile. It will run the code. And because our player will go out of the camera view, we'll just look at the scene. And in order to see what is happening, we should see a message right here below. So we walk into here, yep, this is a player. So if you double-click, we can see on the console in here that this is a player. And if we don't see the console, you can always go to Window general and hit the console. Great. So now we can see the constant that's tried to change this from player. And just for the sake of testing this out, add a space, Save and now let me dog the console may be somewhere in here. When we run the code again, the console is empty. If we walk through into the exit area, there we go. So double-click, you can see the error. And what it says is, let me just docket right here. Player is not defined. Okay, so as you can see, even a tiny space affects the way a string reference is interpreted. So I hope you enjoy it and let's not forget to commit our changes. I'll see you in the next video where we'll learn more about senior management.
19. Scene Manager and Prefabs: Welcome back, my fellow game developers. In this video, we are actually going to use the second scene that we've created, which are the mountains. So now you can see that when we enter the area exit criteria and the scenes, yep, there we go. We go to a second scene, and when we go back, we go back to our old town. But as you can see, there are a couple of slight problems that we need to fix, which are having 2D Jimmy demons, but we'll do that later on. Until then, let's not waste any more time and let's get started. Oh, okay, so the first thing we need to understand whenever we want to be moving from one scene to the other is a seed manager. So in Unity dogs, you can see that we have something called the scene manager. And this allows us to, well, as you can see, manage a her scenes. And we can use many static methods in here, which we will be of course, using throughout our course and whenever we want to develop our games. Okay, great. So the first thing we need is actually a reference to the name of the scene between one to be going to. So back in our area exit, we are going to create a variable in here, and it's going to be a serialized field. We are going to make it a string, and it's going to be called the scene to load, save that. Now, next thing we need to be using the scene manager, but we cannot use it without, first of all, adding it to our library. So remember when I told you we are using the Unity engine and here, if we remove it, you can see that immediately we can no longer use mono behavior or CRO, serialized field, not even the collider 2D. What I did here is I made it a comment so it won't be executed. Anyways, let's continue on. Now we need to add a another library. So we'll call the using. We're going to call the Unity engine again. And now we want to call the scene management. So this allows us to access the scene manager. So what are we going to do? And here we are going to be loading a scene, using this scene to load the string. So if we go back in here, let's go ahead and lower the scene so we can see laws the scene by its name index and the build settings. So you can see in here, where is it? So we can either use a integer to see it in the build index. We'll talk about the built index and just a bit. Or we can use a string with the scene name. So now you know why we created a string and why we need it as a reference. Okay, great. Let's go ahead and use this. So where are we going to call the scene manager and tell him we want to load to the next scene will be doing it in here in the arm trigger enter 2D. After we check that its supplier, instead of printing out something, we are going to call the scene manager. Hey, scene manager. How about we load a scene? He will ask us which scene you want to load. Well, I want to load this seem to load. So we'll save that back in Unity. Let's wait for the code to compile. And before we move on, I just want to say something. Remember when we put a rigid body on the waters? Well, we don't actually needed neither do we need it on the stands. And usually we can keep this, but rigid bodies take a lot of time to compute. So just a heads up. And I could've taken the place where I added rigid bodies and said I made a mistake. But no, sometimes I actually not sure what's happening. There is something that's not working. So I thought keeping this and makes everything transparent and a lot of you are, beginners will think that maybe you're not good enough. Well, there you go. Your instructor makes mistakes. Anyway. Let's continue on in the area exit now we have a scene to load, which seemed we want to load. Again, this is a string reference, so we want to load the mountains scene. We will copy the name back in the area exit. We will paste it in here. We will save that. And now when we run the code, we will walk. When we get to this, I believe we should go immediately to the scene of the tongue. So yep, there you go. We have some kind of error. What is this error? Let's open up the console. It tells us that the sea mountains cannot be loaded because it's not added to the build settings or k. So there is a build settings and this is what the docs referred to when it told us the build. Index. So if you go to the file, appear in unity and we can find the build settings. And this is where we actually build our game. So you can see that we can build it as a Universal Windows Platform, as a PS4 game, as an android and so on and so forth. For now, we will not be bothering with this. First of all, we need to see what's happening in here. You can see that the scenes and build our only the town. So what we need to do is we need to drag them mountains in here. So now the mountains are part of the build scenes, or in the scenes in built. You can see the numbers right here, 01. And this is what we meant by the scene and built index. Okay, with that done, let's save this. We can close this window. Let's hit Run. We walk towards the area exit, and there you go. You can see the mountains have been loaded, although we don't have any players. So what we want to do is we want to keep our player in the game. But what happens when we go from one scene to the next is that all the objects get destroyed. And we don't want that. We want to keep our player alive when he goes from scene to scene. So what we can do about that is if we go into our code, go into our player and start, we can go ahead and tell it that we don't want to destroy on load. So let me just revert that and show you what the intelligent tells us. Do not destroy the target object when loading. And you've seen how convenient is that you could have search on the internet. How can I not destroy an object? When I go to the next scene, you would have got this method and which gameObject don't want to destroy? Well, it's the player. We can simply reference it using the game object. There we go. So this game object references the game object to which this player script is attached. I hope that made sense. So let's save that. Let's go back into Unity. And let's hit Play. So we walk, walk, walk, walk, and there we go. So we are in the new scene with our little statue in here. Now, obviously we are walking through everything because we haven't added any colliders, but at least everything is working fine. Now, what do we want to do next? We want this area exit to be present in our second scene. So it's time for your challenge. And your challenge is to help the player get back. So create a another area exit. First of all, you need to create the game object at a collider, make it a trigger. You'll need to add the script to it, which is the area exit. And you'll need to change the name of the scene you wish to go to. So pause the video right now and go do to each other. Okay, Welcome back. So let's go ahead and create this game object. But before we do that, I want to introduce you to something that will make life easier and that is prefabs. What is a prefab? So a prefab is a previously fabricated objects that we can use anywhere we want. Let's dive just a little bit deeper. So what is a prefab? It's a template for a certain game object. Prefab system allows you to store a game object with all of its properties. So what do we use it for? We use it to reuse a game object configured in a particular way. So for example, we want our player to have, let's say, five hands. So we use it when it's configured in a different way. We can edit many objects at once. So for example, let's say we have multiple items and multiple scenes. We can change the prefab a bit and all the items and all the things will be changed. And we can use the same object in different scenes, much easier. We'll demonstrate this in just a bit. So back in Unity, the way we create a prefab is first of all, we'll create a folder. We'll call this the prefabs. And it's actually very complicated to create a prefab. So the way we do it is we need to check on the area exit object or any object that we want to make as prefab and we need to drag it into the folder. Yep, That's it. That's all you need to do in order to create a prefab. And you know that something is a prefab when you see that, it's just a little bit more blue. So now, if we go into where is it, the scenes? The mountains. Yep, You Can Save. So now if we go into our prefabs folder, we can simply check the exit and drag it in here. How cool is that? So now we have an area exit and our mountain scene. And I apologize for making you go through the whole process. I just wanted to emphasize how important the prefabs are and how much easier they make our lives. So now we can change the name in here. Let's go to the scenes. The town. We copy it because it's a string reference. We paste it in here, we save it. Let's go back to the town had Play, and now we walk the walk. We go to the area exit. We are in the mountains. Now. We walk again till we get to the other area exit, and there you go. But you can see that now we have two players. If we go back again, now we have three players. Again. For now we have four Jimmy demons. And I don't think there is enough place in the world for, for Jimmy demons. We will handle all of that in the next video.
20. Singleton Pattern: Welcome back, my fellow game developers. In this video, we've actually fixed D to duplicate problem. So now let me just make my player a little bit faster. So let's increase it to 50. We go, we are in the second scene. When we go back, there we go. Only one single jimmy daemon. So let's not waste any more time and let's get started. Imagine if he was that fast damped case. So we want to prevent having duplicates players. In order to do that, we need to keep track of the player and make sure that there is only one. And in order to do that, we are going to use something called an instance. So let me show you what an instances, what is an instance of a class? It's a static variable, which means constant across all our projects. It can easily be retrieved from any other class, or it can be more easily retrieved and we'll be using it to avoid finding the object every time we want to play. And we'll be using to keep track of the player and be able to use him, her in from other scripts for the typo. So let's go ahead and use an instance. So back in our code, back and player, we are going to create an instance of a class. And it's going to be public. It's going to be static. As we've said, static is something that is the same across all the platform. It's going to be of type player and we'll simply call it the instance. We'll save that. Now inside of start, we want to determine what the instances, instance equals this. And this references, well, exactly what it says. It references this exact class. So whenever we start again, the instance is set to this particular class which has the player. But now we still have a slight problem when we start the game. The instance will be set to this player, but when another player gets spawned, we will get another instance. So what we can do is let's go ahead and end here. We'll create a condition. So if the instance is different than null, this means that there is an instance. And so as we've said, whenever we have two straight lines, it's an, OR, whenever we have these two squiggly lines, It's an end. The instance is different than this. So this right here, then we are going to, first of all, destroy this game object. Else we are going to create an instance. We are going to set an instance. So what's happening in here is that if our instance is not null and our instance is different than this particular object we are looking at or class, then we will destroy it. If not, if the instance is null or the instance is this one, then we'll simply assign the instance to this. So we'll save that. This is called a singleton pattern. And now when we go back, we will run our game, has our team and walks. He gets to the area, he finishes, now we need to go back. We should have made them a bit faster. So there you go. We have only one demon. And you can see right here, it's under the don't destroy on load paragraph or it's different from the town if you want to think about it. It's as if we've created a different scene where we have this player and the scene is D1 on load, but it's integrated over the town. So now we can even walk back. And there you go. Only one single jimmy Demon. You can see right here and the hierarchy, there is only one Jimmy demon, but there is still a problem. And that problem is that whenever we walk through, we don't want to be flung out the end of our map. We want to actually be right here and this spot as if we naturally entered this area. So we'll do that in the next video. Don't forget to commit your work.
21. Area Enter: Welcome back, My favorite game developers. In this video, we fix the problem of our Jimmy demon appearing on the other side of the map. So as you can see, when we went to the mountains, we are in a good position as if we transition there naturally. And if we try to go back, there you go. We also transitioned to a natural position for our demon to be. And now it's not perfect. It needs a bit of tweaking, but it's working. So let's not waste any more time and let's get started the 0. So our goal in this video is to find a way to make our player appear in a certain position. In the next scene when we move through. So for example, when we enter the mountains from this specific area exit, we want to appear right here next to the area exit on the second scene. And this is very important. So what we can do is we can actually create a game object in here called area exit. And we can set it at a certain position. Keep track of the transition name from area exit from previous one inside of the player, and then put it back in here because the player is never destroyed. Remember that? So it's a good place to store a certain name. And we can, whenever we start the scene, take our player and put his position on the area, enter. I hope that somewhat made sense. Let's do it instead of just speaking about and maybe it will become clear. So the first thing is we want to keep track of the transition name. So in here we are going to create a public String transition name. Ok. And it's going to be public because we want to be able to access it from a different script. Now this is not the best way to do it, but until we learn a better way later on, we will keep using this way. Next thing we want to do is we'll go into the area exit and also create in here a serialized field, which is going to be of type string, and it's going to have the same name, the transition name. Okay, so we'll save that back in Unity. Let's go into our town. And n here on the area exit, you can see that we have a transition name on the player. We have the same but we won't be bothering using it, will be filling the transition name from the code dynamically. So in here, what is the transition name? We want something to represent that it's this place so you can see our map. So we can exit from this place, from this place or from up top. So we want to first of all, keep track of each exit. Second of all, we want to keep track of what is the next location. So the way we do that is we're going to create some kind of naming convention. We will, let's say, call the areas where we can exit from 1, 2, 3, and 4. So the way we are going to name this is, for example, the mountains one. So we know that this area takes us to the mountains one. We will save that in here. Now back in our code and our Onsager enter in here. Before we load the scene, we are going to take our player script. So we are referencing the player script right here, but we cannot use anything inside of it, but we can access the instance. And because the instance references the script, which is this, now we can access any method in here or valuable that is public. So now we can access the transition name. And after accessing the transition name, we are going to set it to the transition name. Now, if you are a bit confused, this transition name references the one hand side of the area exit. And this transition name references the transition name in here in the player script. If you're still confused, you can change the name of the transition name here, something different. So the way you can change a name in Visual Studio is simply hold down control. Make sure you have selected the name of variable you want to change hold down Control, press or, or twice. And now we can change this transition area name. You'll see that it changes in here and it changes all over your folder. So any place where you use this string. This variable, it will be changed. Okay, so control or are. Okay, Great. So let's go in our unity. Now this is not going to do anything. We just want to make sure that our player, so every exit, mountains one went back to blank because we changed the name of the variable here. And ways we run the code and now we can keep track of the player. What does the transition name? There we go. So now when we went to the mountains, it's mountains one. Now, we need to go to our second scene right here, and we're going to create a new game object, which is going to be the area enter, will reset its position. And we'll just position it in front of the area exit and make sure that it's outside the little square in here. We don't want our player to enter and then immediately go back. So we will save this. So now we have an area enter and we're going to create a script. So the way we can create a script, we can simply create area. And third, you can see that in here, it tells us the option to create a new script. Yep, Thank you. The name is Erin, enter, create an ad. And now we have a script of area enter. And we'll use the script to set the player on the exact position of the area enter. So now that the script is loaded, we can open it up. And here we are going to create a serialized field, which is going to be a string, and it's going to be the transition area name. And what we're going to do is as soon as we start our level. So in start, we are going to check if the transition name or transition area name is equal to the player dot instance dot transition name. Then we are going to access the player dot instance dot transform and remember transform. And here is what keeps track of a game objects, of a game object in Unity scene. And the transform of the player will be equal to the transform dot position. And this references the transform of the area enter or the object which has the area under script on it. And we have an arrow. And here the component of transfer cannot be assigned to, okay? So we need to transform dot position, sorry for that, we cannot simply change the transform. We need to access the position. So in here, we can see we have a position and rotation and a scale. So we are actually accessing the position on the transform, on the instance on the player. Okay, great, So with that, let's go back and unity and we'll make sure to call this, what did we call it in the previous scene? Let's go to the town. Yep. Save this area exit mountain one. Let's copy that. Go back to the mountains, the area enter and let's set it right here. Let's save that back to town. Run the code, run the game, and we walk, we go to the area exit. Yep, there we go. How cool is that? So now our player doesn't appear across the map. What if we want to go back? Yep, there you go. This doesn't work in this way and it's going to be a challenge for you. Your challenge is going to be to create a prefab. So create a prefab of the area enter game object added to the previous scene and set it in the position you want our player to appearance. So of course, the area enter should be in a logical position. But anyways, pause the video right now and go do the challenge. Oh, okay, welcome back. So in here, we can Prefab the area Enter and we can then go ahead and added in here and the tongue. But something we just strike now. Well, actually I've noticed before, but I want to tell you maybe you've noticed that every single area exit will have its own area enter. So what we can do, instead of simply prefer being the area enter and then adding it, we can go to the mountains and we can track the area under, under the area exit. So now you can see that area enter is under the area exit, and this is called the child in a game object. So what happens now is every exit. If we move it around, let's say to this position, area enter will move with the area exit and its position right here is referenced to its parent. So the area exit as the parent, the area enter is the child and it's a child parent relationship. We will look further into this in later videos, but for now, this is all you sort of need to know. So area enter is a child of area exit. And we can go ahead and override this yep. Apply everything. So now in our town, safe and our town, the area exit has an area enter and will simply move it to this position right here. So let's look back. Mountains one area, good mountains, one, save that. Back in our mountains. The area exit has a transition name. Does it need to have a transition name? Let's see what happens. In town. We run the code, we walk through, so there is an error. What is the error? If we double-click? Yep, there you go. And there is a null reference exception that me show you what it says. An object reference as not set to an instance. What does it mean if we double-click in here and it's because the transition name is empty. So let's just try and test this out before we try to fix the problem. Yep, there we go. There is a huge problem. We need to change this to mountains, and now we can run the code again. Let's see. Yep, There we go. We go into the mountains. Now if we want to go back yep. We don't go back properly. Why is that? Well, because on the mountains and here we didn't set the correct name, so it should be mountains one. So I'll save that. Don't override everything back down. Hit Play. Walk here. Yep. Yep. Yep. Yep. Everything seems to be working perfectly fine. So I hope you enjoy it. Make sure to commit our changes and I'll see you in the next video.
22. Script Order Of Execution: Welcome back, my fellow game developers. In this video, we haven't changed much. We just learned something about the order of execution of scripts. And we also learned how we can sometimes optimize what we've already created. So now if we run our game, you can see that our demon Jimmy starts off in the area, enter position. Everything works completely fine. If we go to the next area, you'll see that everything is still the same. Nothing has changed, but we just played around and tweaked a couple of things. So let's not waste any more time and let's get started. Oh, okay. So now that we have the name of the area exit and the area enter the same. We want to create a wave to save a bit of time and make things faster with less scope. So an area exit, we are going to get a reference to the area anther. So we'll create a serialized field and it's going to be of type area. And third, and we'll call it the area. And Okay, now and start, we are going to set the transition name on the area. And third to be the same as the transition area name in here. So the area and third dot transition name. So it's not giving that to us because it's a serialized field and not a public. So let's change it to public. Save that back in here. Dot transition area name and transition area name. So let's not confuse things. This is for this one. This one is for this one right here. I'm not going to change the name. If you feel that you do want to change the names, feel free to do that. Okay, great. Now, back in Unity, Let's go into our prefabs and, and the area exit. We can go ahead and the reference. So if we double-click, we can open up the prefab and we can immediately reference the area enter. That is a child of this. Great. So as you can see, the area exit has a child which is the area enter that is right here. We will save that. Let's exit from the prefab. And if we go to the area enter, we can remove this and the area exit, you'll see that it will automatically update itself. So let's keep track of the area enter. We hit play, and there we go. The transition area name as mountain one on the area, enter. Okay, great. So let's try and play our game. Make sure everything is good. Yep, Everything is good. But there is a small problem right here that I've talked about, but haven't fixed or maybe I did. But you can see that there is an error. There is a null reference exception. So the object reference not set to an instance of an object area enter dot-dot-dot. And it says area enter dot start because it is a problem in the area enter. If we double-click, it will take us to the line and it tells us that we have tried to access an instance, but there is no. Now, as you can see, when we play our game, everything is working fine. But if you are very nitty-gritty about things and you want to fix this, we have to fix it. What is the problem? The problem is that the area enter this exact script is loading before the player script. So what happens is, let's say the area enter is created. We start the area enter, but the player hasn't been created yet, so there is no instance. So how can we fix this? There are many ways. I'll show you a very nifty one. And it's something that not many US, it's not that good to do this, but it's good to know you have the option. So in the Edit, go to Project Settings. In here, you can see that we have something called where is it the script execution order? And you can see how each script is executed. So we can add a plus. And here you can see that these are the scripts that we have. Let's choose the player and let's move him up in here. So it starts before the default time. That means it starts before every other script. We'll hit Apply. We will exit. We will run our code and we shouldn't get this error anymore. There you go. But as you can see, our player goes to the position of the area enter, everything works fine, but whenever we start our game, There we go. Our demon is transported to that position. I think this is a good thing because we actually will never start in the middle of a map. So that is, I think, a good thing. Anyways, I hope you enjoy it. I hope you are saving your repositories. And I'll see you in the next one.
23. Section 4: Cinemachine 101: Welcome back, My favorite game developers. In this video, we are no longer static and the work. So as you can see before we add anything, whenever we moved and the swirled, we could only see what we have in front of us. But now as we move, you can see that the camera follows our player wherever he goes. So let's not waste any more time and let's get started adding machines. Oh, okay. So currently when we hit play, you can see that we have all swirled in our scene, but our player can only move in the limited space that we have inside of our game window. But we do want to move through the whole map that we have an interact with different objects. But unfortunately, the camera does not allow this. So what we're going to do is we're going to create a follow camp. So wherever our player moves, our camera will move with none. There are two ways of doing this. The first way is the old-fashioned way, where we create a script we added to the camera, we set a target, and then we need to do a lot of tweaking. And there is the new and more advanced way and that is using a center machine. So what is a sinner machine? I'm going to show you the Unity documentation. So in here, you can see in the unity dogs, you can read all about cinema machines, what they require, what they need. I do think that you should go and look up the documentation. It's a bit long. It's somewhere in here. I don't think you should read everything in there, but at least know what you do have. So let's go back into Unity and let's add a cinema machine. So the first thing we need to do is we need to import a package. So we'll need to go to the Package Manager. We'll go to Window, the package manager and here, wait for the refreshing of the packages, go to the Unity Registry and now and cinema machine that's look for Cinna machine. There you go. Send a machine, make sure to install that. And I'll see you after the installation has finished. O K. Welcome back. So using the magic of editing, I've just finished installing the cinema machine. And now the next thing we need to do is we need to go into our main camera and we're going to add a component to it. And it's going to be a brain. So we'll have a cinema machine brain on our main camera. It will allow us to have co-existing cameras with one of them will be the main camera and the other one will be a virtual camera. So let's go ahead and create one of those virtual cameras. The way we do that is we'll go up here and the cinema machine, and we're going to create a 2D camera, as you can see right here. So now we have this C VCA. And you can see there are a couple of things we haven't here will not go over all of them because there is a lot. But for now, the things that you do need to consider and set immediately is right here, the follow and the lookup. But before we do that, we'll need to create a game object and set both cameras on our child, the cameras to him. So we're going to create a game object. We'll call it the cameras. And we'll just drag the main camera and two cameras. Or before we do that, let me just reset the position and then we'll drag the main camera under cameras and the virtual camp and to the cameras also. So now we have the cameras that hold the main camera and the virtual camera. Now, the next thing we need to do is we need to drag the thing or anything that you want to be following. So what do we want to be following? Well, we want to be following the player, so we'll drag the player right here. So as you can see, we have a couple of guides. And before we continue, let us change in the game window from free aspect to 16 by 9, and this will help stabilize the picture. So we'll save that. And let's hit Play and see what we got. And I'll explain what all of these guides right here or so now if we walk up, there we go, you can see that our camera actually follows our player. How cool is that? So now we don't just walk around and can't see the player anymore. We actually have a camera that's following and you can see how it's following up here through these red lines. So you can see that it's not immediate. So it takes a bit of time and this gives a more natural feel to our game, a more professional feel also. And this is not something that is easily done using scripts. It needs a lot of code and a lot of tweaking. But before we continue on, what are these lungs, you can actually turn them off. If you look right here and the CMV can, you can see or we need to change this. A virtual camera. There you go. So now you can see that if we press on the game window guide, you see that they are all disappearing. And I think we need to copy this because when we stop playing, you see, as we've said, whenever we are in Game Mode, nothing is safe. So that's why I copied and pasted right here. Okay, good. This is something you will understand after many years of experiencing losing all the things that you changed. Anyways. Now, what are these guys? If we scroll down, we can see in here that we have something called the body. And here you can tweak and change a lot of things. Now, again, I'm not going to go over all of them. But a handy way to understand what all of those mean is by simply turning, for example, this all the way up. Now when we run our game, you will see that. There you go. So you can see because we turned the damping, it takes longer for our camera to actually catch up with our player. But when he gets out from the red zone, you can see that it immediately follows in. If we change the damping on the y, we have the same effect. Very nice. Let's turn this back to one. And let's see what else do we have if we move the screen, for example, we can move the screen. So now our player is always on the right, which is something, I'm not sure how you're going to use it, but it might come in handy. We can change the camera distance, but nothing is happening. Maybe that's because you can only use it when it's in 3D. We can change the dead zone and let us try to see how this works. So now if our player moves just a little bit, you can see that the camera doesn't follow. But as soon as he gets outside the dead zone, you can see that the camera starts following. And this is a very nifty trick that you can use in order to implement your camera. Let's turn that back to 0. Next thing, what else do we have? We have other things. So if you move, I'm not sure the soft zone 0. So the southern zone is, for example, let's say the damping is back to 20. You can see the red lines are very farther away. So now, even though we are outside lines, the camera takes time to catch up with our player. I think this is something that we also want to turn back to 0.8, the one, why damping to one. So as you can see, there are a lot of options. There are also noise and aim, and you can even add extensions to them, which I recommend to go and try out research. And now that we've added a follow cam, let me just turn off the window guide. I think that the one that we got by default is good enough for our game for now. I don't want to complicate it a lot, but it's time for your challenge. Your challenge is going to be to tweak your Cinna machine. So play around with the settings and find out where your sweet spot is or how you want the camera to follow your player around. A good rule of thumb as you just saw, if you don't want to read what each setting does, is just to set one to the maximum and try out. So you have doubts about what this thing does. Set it to the maximum. Play around, see what happens and have fun. So pause the video right now and go do the challenge, and don't forget to save your repos. And I'll see you in the next video.
24. Cinemachine Confiner Extension: Welcome back my fellow game developers to one of the biggest videos and this entire course. But we learned a lot. We learned about Cinna machine combiners. We learned about layers. Physical layer is not the old sorting layers. We learned about find objects of type. We learned about get components. So I need your full concentration and around, let's say 16 minutes maybe of your time. So let's not waste any more time. This is a very important video and let's get started. Oh, so currently when we hit play, see that we have our follow cam and everything is working fine. But the problem is that when we get to the edge, we see this blue squares right here. And we don't want that. We don't want to take our player out of the experience. If he can see what's outside the bounds of our game, he will understand it's again. And as you know, whenever you see a glitch in the game and you realize, oh, this is a game. It really takes you out of the experience. So we'll need to fix that. How do we fix that? We'll need to confine our virtual camera. And the way we do that is if we go down here and the virtual camera, you can see that we have extensions. So if we click on that, you'll see that we have something called a cinema machine confined. And as I've said, these are really cool things to look for right here. So for example, if you're doing a 3D game or if you are trying to add a follow zoom and so on. This is a good place to read over these cool features that you have inside the machine. But for now, we're going to add a combiner. So there you go. You can see that when we choose a confining, a new game object or a new component is added to the virtual camera, a component. So what are we going to do in here? Well, you can see that we need a bounding shape. How do we add a bounding shape? We added with a collider 2D. So we'll go to the background layer. We'll add a component. And let's say we want to add a box collider, and I'll show you why this will not work. So now if we go back to the virtual camera and we try to drag the background image, you can see right here that we have a warning that it must be a polygon collider or a composite collider. So let's go back to the background. Let's remove this box collider and let's add a polygon collider 2D. And what's the difference between a normal collider and the polygon collider. Well, as you can see, the polygon collider is much more flexible whenever you want to be adding objects or a collider around an object that is not really a square or a circle or anything else. You can see, you can create it with whatever shape that you want. And if you want to delete one of these sides, you can simply hold down control. And There we go. You can see that we can't delete everything. And let's just make sure that it is right here around the edges and not more. Okay, great, So now that we have the polygon collider, let's save that. Let's exit the edit mode, go back and our virtual camera and drag the background image. Let's save that. But now something weird is going to happen when we run our game. So we hit Play. You can see that our player just went out of the screen. And why is that? Why do you think, or what the problem is? Do you think? Take a moment to think. Time's up. So the problem is, our player is interacting with this polygon collider on the background. The way we are going to fix this is by creating a separate layer for the background image. And I'm not talking about the sorting layer. If we go into the layers right here, go to the edit layers. You can remember that we have something called tags, we have something called sorting layers, and we also have the layers. So previously we've added a sorting layer, and this will allow us to sort which images on top of which author image. But now we are actually going to use the layers and these allow us to interact or allows to determine which collider interacts with which Collider or which physical object can interact with which other physical object. So currently, we're going to create a background layer. And you'll see that our player, for example, is on the default player and so is our background image. So if we change the layer right here to the background, you can see that when we go to Edit Project Settings. Down here, you'll see that we have this really nifty matrix. And what does this matrix me? You can see that we have multiple layers right here and one of them is the background that we just created. So you can see there they are right here on the right. One of them is the default, which is our players layer. And we also have the water if you ignore the re-cast. But for now, what does this matrix actually do? It determines if a layer is interacting with another layer. So for example, the default with the background, they do interact, the default with UI, they do interact and so on and so forth. So what we want is we want the background layer to not be able to interact with anything at all, and especially the player. So what we'll do is we'll simply turn all of these off. We'll save that. And now we know for a fact that the background layer will not interact with the default layer. So our players should not be affected by what happens when he touches the background. So now when we run our game, we should see that our player is no longer outside the bounds of the map. But if we go outside, will it go past it? Nope, As you can see, well, something went wrong. We want to the next level, but as you can see, now, if we go down through the waters, we are no longer going outside the bounds with our camera. Now, our player is still going outside, but no worries about that. You can see that our camera is no longer following him. And we really can feel that the environment which we are in is the environment of the whole world. And this really adds a lot of authenticity to or gain. Now, if we go to the next level, you might have noticed a small problem. And that's that we don't have a virtual camera running here. But the other problem, if we go back to our previous scene, again, as you can see, there is no longer a virtual camera, even though we have it right here. And the cameras, the virtual camera, but there is nothing to follow. The transform that we use to follow is now missing. So how are we going to get past this little problem? Well, we'll need to create a camera controller in which we will access the center machine and access the player inside of our game or find our player inside of the scene and then assign him to that virtual camera to follow. So how are we going to do this? First thing is we're going to create a new Sharp script. So we'll go to Create C Sharp. Can controller. Hit Enter, wait for it to compile. And I'm not sure what just happened. Next thing we'll do is we'll add it to our virtual camera. So now our virtual camera has a cam controller script on it. We'll double-click, open it up and Visual Studio. And the first thing we need is just like we added a where is it in the area exit. We've added a scene management in order to access the scene manager Library. And here we are also going to need to add using center machine. So now we can access components on a single machine. Next thing is we need two variables in here. One of them is going to be a private player, and it's going to be a player target. And you might be wondering, Michael, why didn't we make it a serialized field or a public? The problem here is that we don't want to manually attach our player to the target. We want to have it dynamically happen in our script. So I'll show you what I mean in just a bit. Next thing we want to do is we want a cinema machine, virtual cameras or sin machine virtual camera, and we'll just call it the virtual camera. There you go. Save that. Now and start. We are going to use a method that will allow us to find an object. And if we go in the documentations right here, I'll show you how a master problem-solver finds this. So let's say we want to find the player. How do we do that? Well, Google how to find a object and Enter. There you go. You can see that we have something called the game object dot find. If we click on it, you'll see that we can find a game object that we need. But there is a pattern method that I'll show you and it's the Find object of a certain. Type in Unity. Hit Enter. Whoa, there is a finite object of type. So enter it. What does it do? Well, it returns the first active loaded object that matches the specific type. So we want a specific type which is the player, and you can see how we can use it right here. Okay, great. Back in our script and I recommend you take a little bit of time to look through this method will access the player target. So the player target, that's the name of the variable we've created up here. It's going to be equal to phi1 object of type. And which type do we want to look for? It's the player. So by calling the script of player, we actually get the object of the player. And now we can attach it to the camera. But before we do that, in order to access the virtual camera, we need to actually assign it. And because we didn't create a serialized field in here, we're going to need another method. So we have the controller which is attached to the virtual camera. But what we want is we want to access this object right here, which is on the follow. We want to access the cinema machine virtual camera component. And we can actually do this in a very handy way. And that is by getting the component. So using Get component, the cinema machine, virtual camera. And now all we have to do is get the virtual camera dot follow. So we're accessing the follow. And then we are going to assign it as the player target. But not just that, because a player target is just the object we found, we need to actually access the transform. So let's save that and let me just explain one more time what is happening in here. So first of all, we created these two variables, one of them as a private, we can also make the swan private, but no worries it is. So a private player target and a private virtual camera. Then we found that game object. And why are we trying to find the game object and not assign it manually? Because we want it to happen dynamically. We don't want to go into every single scene and assign the player to the camera in every single scene we wanted to happen dynamically. Then we used a method that gets a component. And because the controller is on the virtual camera and it's one of the components. We have another component which is the cinema machine virtual camera. We access it and assign the next thing we access the follow. So in here you can see we have a follow. We access that using the right here using this little dot. And we assign the player target HDL transport because we just have the object, not the actual transport. Okay, so if we save that, go back into Unity. Let's set this as none. Save that Play. And we should see right here that the player has been found and has been assigned. So now when we move around, you'll see that the camera follows our player. But if we go into the next scene, you'll see that nothing happens and that's because we don't have a virtual camera. So how are we going to fix this? We'll go into the prefabs. We'll set the cameras as a prefab, will save that. We'll go back and scenes to the mountains, will delete the main camera. And we'll get the prefabs and add the cameras that we have. We'll save that. We'll go back into our town, will run the code. We are going to walk to the mountains and there you go. As you can see, we have a follow-up cam. Now we don't have a confessional, we will add it later on, but it's working. How is that? So I hope you enjoy it. I hope you are saving your repositories. As you can see, our project is taking shape and it's becoming very big. You should be really proud of yourself and how much you've accomplished so far. So I'll see you in the next video.
25. Tilesets In Unity: Welcome back, my fellow game developers. In this video, we are going to learn how to create tile sets from the slice sprite sheets that we have. So what we did is we got a sprite right here, a complete image of the tiles that we want to use. We sliced it up and we converted it into tile assets. And these assets are now present right here and our tile palette. So let's not waste any more time. Let's get started. Oh, okay. So currently, as you can see, we've always been working with a background image. So it's an image where we already have some kind of predetermined path. We have predetermined objects and our world. But this is not fun whenever you want to create your own levels, it's always better to have a way of using some kind of tiles. Maybe we'll see that later on in order to create your own map with your own layout. So how are we going to do this? Well, first of all, using Sprites, then dissecting or slicing the sprites, and then using those sliced sprites in order to lay out tiles and our world, maybe you're a bit confused by what I just said. So let me explain that a bit better. First of all, we get our sprite sheet. So just like we had the Jimmy demon sprite sheet, we also have a sprite sheet for our tiles. Next step is we are going to slice up the sprites. Then we are going to convert these sliced sprites and to tile assets. We will add the style assets to a tile palette that will enable us to draw on top of our scene using a grid layout. And we will have a tile map with our daemon on it. So take just a moment to understand the process because we are going to go through it right now. So back in Unity, and here we are going to go to Windows 2D and we're going to call 40 tile palette. And this tile palette allows us to draw, or it's just like a painting palette whenever you want to paint a picture, this is a tile palette that will allow us to paint different tiles on our C. Okay, so now we need to get our tiles. And you can see that in the resources I've left you the files to use, which is the path and objects, and this is the file set that I am going to use. We will have other tile sets later on. But for now, the pant and objects is what I'm going to be using. So what we'll do in here is we'll go to Assets, will create a new folder for the files. And in here we are going to go ahead and drop the path and objects. So we'll drop it in here. So as you can see, if we double-click on here, it's a sprite with all the tiles that we want. Now the next step is to go ahead and slice them up. So we'll go into the Sprite Mode, choose multiple, apply the changes. You go to the Sprite Editor. And in here we are going to slice them up. So I don't think automatic isn't going to work. 64 by 64. Let's try that. No, we need to have this style, for example, this stone and the grass got into nine pieces. So let's try 32 by 32. And yep, there we go. You can see that it's cut into nine pieces and we can use it. So we'll hit Apply. And now you'll see that instead of a single image, we will have all of the little sprites cut out all of the slices from our big spreadsheet. Okay, great. So these are the first two steps. The next step is to create tile assets and add them into the Tile Palette. And the way we do that, if we go back into Unity, and here we have the Tile Palette. So we need to create a new tile palette. We'll call this the path and objects. We'll hit Create and we'll go to the assets inside of tiles. Let's go ahead and create a folder, paths and objects. And we are going to select this folder right here. And we'll also drag the sprite in here. So now we have the Style palette created, but now we need to create the file asset. So the way we do that is we'll take this entire image and we'll drag it in here into the tile palette. We need to select a folder. And let's go ahead and select the path and objects inside of the file. So make sure that you save in a folder where you can have all of the tiles. So select the folder and wait for the importing to have. So now the sprites are being converted into tile assets. And there you go. So as you can see, these are the tile assets and you can read right here in the inspector that this is a tile. So each one of these is a tile and you can see them right here in a tile palette. So now that we have everything set up, the next thing to do is to create a tile map, but we'll do that in the next video because this one is already too long. And before I go, I want to issue you a challenge. So your challenge is going to be to create your own tile map or offset for now. So import whatever sprites and tiles you choose to use for your game. So slice the spreadsheets from the tiles and added to the tile palette to create your new tire set. And before I go, I also want to show you where I get my tile sets. So this is my spreadsheet. So it's open game art. As always, it's an amazing resource for anything that you need to create your games. It's from the author, Sabine. I'm not sure. I recommend you check them out. And you can also go to open game art and find your own style set so you can go to the browse, to the art. There are tons and tons of biases, as you can see right here, Zelda like blocky dungeons and so on. So find your spreadsheet, your preferred sprite sheet and use it to create your pile set. So I'll see you in the next video where we will start laying out our tiles and creating a tile map.
26. Creating a Tile Map: Welcome back, my fellow game developers. In this video, we've actually created a tile map. So now let me just move my player a little bit on the road. If we run our game view, you can see that this is the map that I've created. So there you go. You can see that we have solid objects that we interact with. We have shops, we have everything. There are a couple of things that we'll need to change. For example, we can see that we have the waters in here. We have the sacks of potato and we have the body of water which we cannot cross into. So let's not waste any more time and let's get started. Oh, okay. So before we continue on in here, when we want to commit the changes after we've created the tile assets, there is a small problem. If you've already staged or committed all your files, that's okay. But if not, I do recommend that you ignore everything under the assets, styles, and path and objects. And why is that? Well, because I don't think it's really necessary to go ahead and save all the assets. It's a lot of space, and I don't believe that it's very necessary. Only the code and what happens inside of the game are more important than the actual images. So we're going to be ignoring everything under Assets, file path, and objects hit Okay, so now we can stage all of our files and go ahead and commit our changes. So I created a tile set. Don't worry about if you've already done this. No worries. Just continue on back immunity. Now it's time to start painting. So how are we going to paint using our new tile palette? Well, first of all, we're going to go ahead and create a new scene. We are going to go ahead and make sure it's 2D. Save the changes. Our scene right here. And now we are going to go into game object. We are going to go into the 2D and find tile map, make sure it is rectangular. Hit Enter. And now we have a tile map. We can change this into the background. And you'll notice right here the active tile map will become the background. There you go. Let's save the scene. And I think we're going to call this the town too. So Control S to save the scene. And cytosines will call this the town to save. And now we have a second time. Now, how are we going to draw in here? So for example, if we zoom in, we can choose one of those styles. And let's talk about the options that we have up here. We have, first of all, the select an area on the grid. And let me make this a little bit bigger. We can select an area on the grid, and this is for editing. So for example, if we hit the Edit key right here, select this grid, had the move. Now we can move this palette. We don't want that for now. This is the move of just saw what it did. And we have also the brush, and this will allow us to paint things in our world. So if we choose this, for example, this kind of stone, we can start painting. But obviously you can see that the sprites or the tiles are too small. How do we fix this? If we go into the tiles bath and objects, if we hit the big sprite, we can change this from 100 to 32. Hit apply, and there you go. We have the tiles now big enough. We can also change the filter mode to point no filter. And this should make our tiles just a little bit sharper. Okay, great, So now that we know how to use the paint, next thing to learn how to use the paint filled box. And this allows us to create boxes in our game quickly. So as you can see, we can paint multiple blocks very quickly. Okay, great. Next we have the stool. I've never used this tool. It's a bit confusing. And we have the eraser, which is extremely important. Okay, great. So now we are going to create just a small example just to test out a couple of things. So I'm going to create a small road in here. Then we need to add the grass on top of it. So as you can see, this is the block that we can use in order to draw grass. So we draw on top of it right here. There we go. We draw some grass under it. And let's say for example, we want to make some kind of curve. So let's save the road goes this way. So how are we going to make sure that it looks authentic? Well, first of all, let's add a grass in here. Let's add the grass to the right. And To the left. But what are we going to add and this block, or in this block? Well, you can see that we have this one for here. So there you go. You can see it naturally curves. But what about this one? We can't use neither this one, nor thus no any other. Well, if we go down in here in our tile palette, we can see that we have, for example, this type of grass. And if we added in here, there we go. We have a really nice curve upward. So this will take a bit of time to understand, but once you get the hang of it, it will become very easy. So for example, if you want to create a bunch of dirt, we add this kind of blocked to the grass and then we fill out everything in here. So now we have a dirt road or ADR, just just dirt on the ground. Okay, so next thing is, let's say we want to add these sacks of potato so we can choose multiple blocks and we can start painting them. But obviously there is something wrong. The background of these potato sacks is transparent, so as you can see, it is painting over our backgrounds. What are we going to do about this? Well, we can create a second file map. So if we go into the grid, we right-click and go to the 2D Tile Map rectangular. And let's call this the objects. So now we have a second active tile map in here, which is going to be the objects. You need to always make sure which active tile map you are working in. So I'm going to delete the sex for now. I'm going to add the back ups. This is not the dirt that we are looking for. So we'll add this dirt back in here. And now we need to add the sax. So instead of background, we'll go to the objects, will select the bags. And now you'll notice that we can paint the bags without having any trouble or any inconsistencies in our world. And just to make sure that the objects are always over, the background, will go to the objects, will choose the background layer as the sorting layer, and we'll write one. And here I'll also go to the background. We'll make sure it's a background in the sorting layer and its order and there is 0. Let's save that. And now you can see how we can create our files. Now, let's test how this world works for our player. So if we go back into our previous scene to the town one or the regular town, we are going to go ahead and the prefab, our player. So now we have a player as a prefab and we'll go back into the scene. It down to we'll remove the main cameras and we'll add our own cameras. So these are the virtual cameras with a follow can and we'll add a player. So now when we save, we run the game. You can see that we can move with our player and we have a fall camp. Great. Of course we'll be expanding our game later on or expanding the map, making it better. But for now we need to do something very important. And that is makes sure that our player interacts with these bags and doesn't just move through them. And we can keep adding colliders. We have a much better way. So how are we going to do this? Well, I'm going to issue you a challenge. So adding colliders to solid tiles. So add a tile map collider, two solid objects. So the objects tile map that we have right here, you'll need to add a collider to it. Then you'll need to add a composite collider. I'll explain what that is later on. You'll need to add a Rigid Body 2D and run the game and notice how everything works perfectly fine. So pause the video right now and go do the challenge. Oh, okay, Welcome back. So let's go to the objects. And you will notice that these are the objects right here. We're going to add a component and it's going to be a tile map collider 2D can see right now, there you go. You can see that the bags right here have a collider on them. And for example, let's say we want to add a bit of water in here. And it's going to be under objects because we don't want to be moving through the water. So I'll just add a bit of water right here, and there you go. So now when we run our game, you can see that we can no longer move to the water nor weekend go on the backs. Okay, great. So now this works perfectly fine, but there is a slight problem. As you can see right here, we have medical loggers on this body of water. And this takes up in a lot of memory and our gain. So what we can do is add a, where is it the composite collider? And you'll see what happens when we add a composite collider 2D. You can see right now that a rigid body 2D has been added and entire map, if we click on the used by composite, notice what happens to the files or the colliders on all these styles. There we go. So now instead of having 40 colliders, we have one single collider that is composite over all of the bags or I mean all of the body of water. So again, if we run the code, you'll notice that because we've added a rigid body and this is what I meant when I told you everything shouldn't be working perfectly fine. This is not working because the body is falling, because its dynamics or let's change it to kinematic. Run the game. And now everything should be working completely fine. So very nice. As I've said, it's not very complicated. It's easier than you might think whenever you want to be drawing your tiles, you'll get used to it. Make sure that you are always on the correct active map. So make sure to commit your changes. Create a map that you want to watch ever mapped you want using the tiles that I've provided you or any trials that you found on open game art or other websites. Will that said in the next video, I'll have one prepared that we can use and I'll see you then.
27. Keeping Player Inside The Map: Welcome back, my fellow game developers. In this video, we are going to first of all bound our cameras. So as you can see, the camera no longer goes out of the game scene. And not only that, we also clamped the player's position. So as you can see, he can no longer go outside the map that we have created. So let's not waste any more time and let's get started. O k. So currently we can move around and our new create a tile map. But the problem is that the player goes out of the map and the camera follows him there. As you can see, we can walk outside the map and see the blue background in here and we don't want that. Before we do that, I just wanted to show you something that I did. I've added an extra tile set in here that is the background on objects. And you can see it's on the sorting layer background and order Layer 2 without any colliders. And that's for objects on the background. So I mean background on the object. So for example, I wanted to draw a bit of the wood on water and bolts on water. So I've added this background objects just for that, or background on objects. I also made sure that I can walk on the pad right here. Okay, so let's continue on. How are we going to, first of all, make sure that the camera doesn't go out of bounds. Well, you already know that we need to add a polygon collider. So we'll add to the background polygon collider 2D. Let me just fix this up real quick. So we'll edit the polygon. There you go. Put the edge in here and edge appear. An edge peer. And one edge down here. We'll save that will open the virtual camera. And where is the confined? There is a confinement right here. Let's drag it, save that, and there you go. Now we have a combiner. So if our player hoops, so we forgot to make sure that this polygon layer is on the background layer and it doesn't interact with the player. Again, we run the code and we can see that the camera no longer goes out of bounds, but the player can still walk away from our scene. So how are we going to fix this? Well, we'll need to create a way for the player to know where the bounds that he can walk over r. So we'll open up the script and the player script will need a couple of variables. So we'll need a private vector 3 because we need the position of the bottom left edge of the screen. And we'll also need a top right edge. So top right edge. Okay, so now we will have both edges of the map available to the player. How are we going to actually get those? So we'll need to get access to the tile map that we're working in. So in order to access the tile map, we will need to be using the Unity engine. Dot tile maps. There we go. Let's save that. Now. Next thing we'll need to do is create a variable in here, which is going to be a serialized field to reference the tile map. And we'll just call it the tile map. To keep everything very simple. Maybe let's just keep the tile map like that, save that. And now we'll need to make sure that we assign the right tile map. So we'll need the background for our player. So back in Unity, wait for these crypto compile. Go to the player. And where is the script? There you go. We have a tile map. Drag the background, and here, save that back in our script. So what are we going to do? Well, first of all, we need the edges. How are we going to get the edges? After we initialize our player in here, we are going to go ahead and call the bottom left edge. And it's going to be the tile map dot local bounds that men. So let me just go back and try this one more time so we can read the minimum point of the box. This is always equal to the center extended. So this will give us the lower bounds. It's the bottom left. Now we'll try the top right edge, and it's going to be the tile map dot local bounds. You've guessed it at the max, and this is the maximum point of the box. Okay, so now we have the top edge, the bottom edge, and we can use those to determine where the player can walk. We'll do that in the update right here. So we're going to first of all, access the transport of the player's position. And we're going to use a method that is called let me just create the new vector 3. So this is where the player will be able to walk. But how are we going to make sure that the player's position never goes out of bounds. So in the update, we keep track of the player's position. So as he walks around, let's say, and we noticed that his position is at the edge of where we can walk. We want to make sure that he can never exceed this point right here, or this point right here or up there. So how are we going to do this? There is a very nifty method that is called the Math dot clamp. And you can see what it does. It returns a float. And a float is the result between the minimum and the maximum value. So clamp gives a value between the given minimum and the given maximum. So what we can do is make sure that the player's position never exceeds a certain clamped variable, which will be from the minimum to the maximum. And you can read more about clamp and how it works. So this is the value that we provided with. It's going to be the position of the player. The minimum will be the bottom left edge, and the maximum will be the top right edge. So let's go ahead and try to implement this in our game. So first of all, because this is going to be very long lines, we'll hit Enter and start writing in here. So because we are taking our players transform position, it's a vector three as we've learned because we are working on the x, y, and z-axis. So the first thing we need to do is we need to clamp the transform position of the player. And let's see how we can actually write math after the clamp. You can see that we need to write first of all f dot clamp and then add the values. So we're going to write math F dot clamp, and we'll open up the parentheses. What is the value that we want to provide? It's going to be the transform position dot x. And what are, what is the minimum value is going to be the bottom left edge dot x. And what is the maximum value is going to be the top right edge, the x. There we go and we need to add a comma in here. Now the next thing to do is to continue with the y and the z position. And it's going to be part of your challenge. So your challenge is to finish the rest of the clamps. Clamp the position of the player on the y and also on the zip. So this is a fairly easy challenge. Pause the video right now. If you want, you can read more about clamps and unity dogs and go to the challenge. Okay, welcome back. So I'm just going to go ahead and duplicate this two times. I'm going to remove the last comma. And instead of position dot x, I'm going to use the position dot Y and instead of position x near deposition dot z. And of course we need to change this in here also. So dot y. But y and the z, or z or whatever you call it, make sure to save all of that. And if, let me just put this back in here, the way I did this is by using tab shift to untap, but this looks more organized than if we put everything on a single line and had a really long line. Okay, so with that done, let's go ahead and run our game and see if that works. So we'll save all of that, run the game. And now as our player walks, you'll see that when he gets to the edge, there you go. He can no longer walk through there, but there is still a small problem we are using. So as you can see, the player can go out of bounds a little bit. And this is not very nice, especially when he's down at the bottom. We want a way to be able to make sure our player is still showing in our game window. So the way we do that, I can just stop our game back in our code in here and start where we said the bottom left edge and the bottom right edge. We are going to add something to this. So it's not just going to be the upper bound, I mean, 40 bottom left edge or the lower bound. We are going to increase it by just a little tiny bit. So I'll create a new vector 3, and we'll just add 0.50.5 f and 0 F on the set. And we'll do the same. Let me copy this and set it in here. So there you go. We'll save that. So what happens now to, in order to assign the top right edge will take the tile map to local bound max. We get the upper bound and we just decrease it a little bit. And this in here should be minus and minus. So we decrease it just a little bit so the player doesn't hit the actual edge. He hits an edge up here that is just a little bit down. Okay, so now we can go ahead and run our code and see what happens. So as our player walks, he should start. Oh, there you go. So you can see that the player stops before he actually goes through. And why was he going through? You can see that it's because the position is in here. So this is the center of the position. So now this little distance in here is the 0.5 that we've added with the vector to that. Strike this on the bottom edge. And there you go. Let me just back to the player versus player, player and the position. There you go. So you can see that the player is still showing. We might need to add a little bit more in here. Let's try the top. And if we go to the top, yep, there you go. I think we need to add just a little bit to the top and the bottom. So try to fix this. Maybe make this 0.8 by in here 0.8. Let's save that. Try this again at R1, move our player to the edge. You can see it's the same to the bottom. It needs a bit more to the top. Yep. The top I think is good enough. Maybe we'll make this one. I'm going to stop the video right now. And I hope you try and add your own edges in the next video, we are going to be creating a level manager and learning about methods in Unity. So I'll see you there. Make sure to commit your changes.
28. Creating A Second Level: Welcome back, my fellow game developers. In this video, we are going to be creating a second file map. So as you can see in here, we've created this map, we've added the grid, we've added an area, exit and so on and so forth. Now, I'm not going to do everything in front of you because the steps that we are going to do are extremely basic and there is nothing new to learn. What you'll need to do are first of all, you'll need to add the mountain sprite that I've provided you with. You'll need to set it to 32 or it depends on your sprites. You'll need to make sure that the sprite mode is multiple. You will need to apply that and make sure that the filter mode is point more filter. And then you'll need to go into the Sprite Editor. You'll need to slice all of these up. And if you're using the same tile map as me, you need to use. I think 32 by 32 is the way you slice them. So when you have everything sliced, you'll need to add them to your tile palette right here. You'll need to create a new tile palette and add the entire tiles and here. So with that done, the next thing you'll need to do, and this is a very important step, is you need to go into the visit in the town too. Save that. Yep. Keep safe. You'll need to Prefab the grid. And why is that? Because if you see in here, the grid has the background, the objects, the background on objects. And we have the polygon colliders and the tile map colliders and so on. And we don't want to keep doing that. But the only difference is that you need to unpack the grid completely. So what do I mean by that? Let's say we are in the mountains two, we want to start off our game. But when we add the grid, for example, if we go into the Prefabs and we add our grid, you'll notice that it is the same as the previous one. And whenever we want to make changes to it, there will be a slight problem. We don't want that. The way we unpack it is we right-click on the grid, we go into the Prefabs and we select unpack completely. So now we'll be able to make changes to this grid without having any kinds of errors. And this is a very important step. So make sure that you right-click. So now it's not anymore. So you right-click, go to prefab and unpack completely the grid and then you will be able to continue on working. Again. Another thing that we need to make sure of is the, when you click on the background, you'll notice that the edges in here will be kind of all over the place. So you'll need to go into the tile map renderer, I mean the tile map and you'll need to compress the tile map bounce after you finish laying out all of your piles. So that's basically it. You will also need to change the polygon collider, make sure it's set up correctly. You'll need to add the confined right here. So drag and the background will later on find a way to do this more easily. Save that. And that's basically it. That's all you need to do in order to create a second pile map at the grid on packet completely and start painting. So with all of that said, I'm going to issue you a challenge as that is to create a second or a second scene or whatever you want to call. So create the tile assets from the sprites, Prefab the grid, create a new scene at the grid in the hierarchy, and unpack the grid completely, so that doesn't create your level. So pause the video right now, go create your level. And I'll see you in the next video where we will create a level manager.
29. Level Manager: Welcome back, My favorite game developers. In this video, we are going to be creating a level manager will learn what it means when we want to delegate scripts, where we want to create different scripts for different things to do. We'll also learn about methods and public methods and how scripts can communicate with each other even though they have private variables. So let's not waste any more time and let's get started. Oh, okay. So currently we can see that when we run our game, everything is working fine and we can move from one level to the next. Now we have a small problem that the camera is not following the player when he goes to the next level. But we'll fix that later on when we learn while loops. For now, let's focus on creating a level manager. Why do we need a level manager? Well, when it comes to programming and creating games, specifically, you always need to find a way to delegate your code. So we don't want our player to always be keeping track of everything. We want our player to have to deal with finding the bounds of our level. So what we'll do is we'll create a level manager that will do that for the player and then send the information of the edges to the player using methods. So let's first of all create a level manager. So in the hierarchy will create an empty game object. We'll call it the level manager, and we'll reset its position 2 000, 000 on all sides. Next, we are going to create a script. So in the scripts will right-click create a C-sharp script. It's going to be called the level. And without any spaces, manager hit Enter. Wait for these crypto compile. We will add it to the level manager and let's go ahead and do prefer. But before we forget, because we will be needing the level manager and all of our scripts. Now, let's open up the script and let's see what we are going to do here. So the script will be responsible for determining what the edges are of our level. So first, of course, we'll need to add a file maps. So this will give us the ability to access tile maps. Next, we'll need around the same variables that we have and the player. So we'll just copy these and paste them in here in the player. And let me just move this up in here, Enter, and there you go. So now we have a reference to the tile map, the bottom left edge and the top right edge. But you might be telling me right now, how are we going to communicate between them? Or even before that, let me just remove the burden from the player. And I just got them using Control X. And I will paste them in here and the start. So whenever the level manager starts, it gets the tile map that we have in here and it sets the bounds of it. Okay, great, So now that we've finished with that, you might be asking me, Well, Michael, how is Player going to know what the bottom left edge are and what the top right edge is. So even though we have this private and we have these in here also private, how are they going to communicate? Well, they will communicate using something called a method. Let me explain what methods are. So just like a variable, methods also have a similar structure. First of all, we have the access type. It's the way accessibility of our method. So can we access it from the same script only? That means it's a private. If we can access it from multiple scripts, that means it will be a public. Next we have a return type. So just like we have a variable type, we also have for a method, a return type, and it can return a string and integer, a float. So when we finish calculating things in our method, we can return them. Next we have the name of our method. And just like we name our variables, we also have a way of naming our methods by always making every single word of the method be capitalised. So adding velocity, the a and the v are capitalized and we also Always name our methods by what they do. So adding velocity at velocity. And finally, a very powerful tool of methods is that we can send parameters and to them. So if we, for example, need to have two things that need to be calculated, we can send them in the parameters and in the other script, we can calculate them. We'll see how all of that works when we do an example. So back in our script in here, we can actually remove the tile map because we won't be needing it in the player. And the using library to save a bit of memory. So we're going to create a method and the player that we'll be able to accept the bottom left edge and the top right edge and set them. So we'll create a public because we want to be calling it from the level manager. We are going to make it void. And then we're going to call it the set limit. And this set limit is going to take two arguments. The first one is going to be a vector three, and it's going to be the bottom left or the bottom edge to set. And another one which is going to be the top edge to set. So now that we have these variables being passed in, we can access the bottom left edge of our player or the variable on the player up here, this one. And we are going to set it as the bottom edge to set. We'll do the same with the top edge. Top right edge is equal to the top edge to set. Great. So as you can see, we have a public method which has no return and it's called set limit. Notice how set, how the S and V are both in the uppercase. We have two arguments that are being sent in here. And we are setting our variables based on the arguments or the parameters that are being sent to it. Now the next step is to actually call that method in level manager. And I'm going to issue you a challenge to do that. So you'll need to call the method set limits. First of all, go to the level manager script, access the instance from the player script, access the method, set limits and give it the parameters. So whenever we finally set our edges, using the level manager will need to call the method player and tell it that these are edges. Here you go using the parameters. So pause the video right now and go do the challenge. Okay, welcome back. How did you get on with that? So first of all, we are going to access the instance of the player. Then we are going to call the set limit. And in here we'll need to pass the two parameters. So the first parameter is going to be the bottom left edge. The second parameter is going to be the top right edge, and we'll save that. So now what happens is when we run the game and the level manager starts, it takes the bottom edge or it calculates the bottom edge. It calculates the top edge, it calls the player, it accesses the instance, it sets the limit, which is the method in here. So it calls the method in here and it sets both of these parameters. So what happens then when we call this method, we jump into the player script. We set the bottom left edge, the top right edge, and now we can use them in here. And this is just a small line that are used in order to make sure everything was working correctly, will save all of that. And now let's go into our game and see if that actually works. So level manager should have a place for us to add the background. We'll set it in here, we'll save it. Let's see if that works. So we run the game and there you go. Yep, there you go. We can walk down in here. Now, let's go into the second scene, the mountains. Let's add a level manager in here also. And let's give it the background. I said that save that. If we run the game. Let's see if we can walk out. No, there you go. We do not walk through everything. How cool is that? And a, another very important thing to know is that if we save these variables on the player and the player doesn't get destroyed, the values of the map are not changed. So it's very important to have a level manager separated from the player. Now, the final thing we need to test is if we go from town to, to the mountains, Let's see. When we go. Yep, we can see that we don't have the camera following the player. We will fix that, as I've said, using the while loop when we learn them. But as you can see, we can not cross the edges, neither on up edge, neither on the left, and neither down on the bottom. So with that done, I hope you enjoyed. In the next video, we are going to be learning about Canvas in Unity. I'll see you then. Make sure to commit your changes.
30. Canvas in Unity: Welcome back, my fellow game developers. In this video, we are going to be creating a fading image. So as you can see right now, we have something called a canvas with an image inside of it. And when we hit play, you'll notice that we slowly fade and now it is not perfect, but at least it somehow works. Don't worry about it. We will be fixing all of that. So let's not waste any more time and let's get started. Oh, so currently, when we run our game, when we go to the next level, you can see that it is instantaneous and it's very fast. And honestly, we don't want it to be like that. We don't want it to be that fast. What we do want is to have some kind of fading in and out. And the way we do that is by creating an image, a big black image in here that will cover the entire space of our level or the entire space of the camera. And when we transition to the next level, we want that image to appear and then disappear. So let's get started. First of all, we need to create an image. So if we right-click in the hierarchy right here, go to UI. We can go ahead and create an image, hit Enter. So as you can see, we've created something called a canvas and a image. And you'll notice that this image is a huge. And if we double-click on the canvas, you'll notice that the canvas is even bigger. So you might be thinking, Well, why are they so big? But don't get misled. They are actually extremely small. Because if we click on the image and we move it around, you'll see that it's very small compared to our player. While the player and we look in the scene is extremely small compared to the image. So what gives, why do we have this weird scaling between the canvas and the game? This is a way for unity to know how things work. They preferred to keep everything in the UI big so we can easily control it. And on the meantime, it just affects the camera and everything in front of it. So don't worry about that. Now what we're going to do is we're going to use this image and stretch it out so it covers the entire canvas. You can see that the bigger we make it, the bigger and more space it fills. Now we can take this to the edges, but let me teach you a very cool way. If we look right here on the right, there is something called the anchor point. So if we click in here, you can see that the way we can anchor it, you'll notice these white thin lines. And I'm not going to go too deep into that because if I want to explain everything in the UI, it can take a course on itself, but we'll just learn the basics if we hold down Alt. And we can see that everything changes when we hold down Alt, we click the bottom right edge. You'll see that it immediately goes over everything. So this is a very cool and nifty way of doing things. Next step, we'll click on the image and we'll change the color. So in here you can see that we have image color. We'll click on the color and we'll make it completely black. Okay, good. So now we have a black image in front of our screen that doesn't go away and will need to, of course, change that. How are we going to do this? So first thing first is we need to create an animation that will take this from completely black to completely transparent. So how are we going to do this? If we go into the image, add a component. We can add a canvas group. And what this canvas group does is you'll notice it has an alpha. And here, now we need to turn off the block, re-cast and turn off the interactable. And you can see that the alpha is at one. But if we drag it down, you can see that at 0 it is completely transparent and that one, it is completely non-transparent. I guess that's what you call it. So we are going to manipulate this using animations in order to fade it in and then fade it out. So let's get started. We're going to create an animation. So we'll right-click on the image or will actually whereas the animation, we have lost it. No worries. We'll go to the animation at the animation tab. And let's just, let me just move this, but set it right here next to gain, select the image, create an animation. And where should we go with this will go into the animations, image fading and side OVA file. And we're going to call this the fade underscore. And so this ends the fading. And we'll create another animation. So we'll go in here, create a new clip. And this is the fade underscore stopped. We'll save that. So now we have two animations. How does the fade start works and how can we actually record it in here? So first of all, the fade starts, goes from one to 0. So we start off at one. When we get to the 1 second mark, we wanted to go to 0. So if we click in here, we can hit this little red record button. We can go to the end and we can set this to 0. So now what happens if we run our game? You can see that it goes from completely black to completely transparent. Then we clicked back on this red button and it goes away. Next, we are going to go into the fade end and we are going to do the complete opposite. So we start off at 0, we need to hit the record button. We go to the 1 second mark and we're going to set it to one. Save that, remove the record button. And now when we hit play, you'll notice that it goes from completely transparent to completely black. Okay, great. Now that we have set up our animations, the next obvious thing to do is to go ahead and set up the animator correctly. And for that, I'm going to issue you a challenge. And your challenge is going to be to make the image faith. So go into the animator and said The Fate start as the default state, then create a transition to fade and it should have no exit time and a transition duration of 0. Create a trigger parameter called Fade start and set it as the condition on the transition. So pause the video right now and go set up the animator. Okay, welcome back. How did you get all of that? So first of all, we'll need to set the faith start as the default layer or default state will then create a transition to the fade. And we are going to remove any exit time and we are going to set the duration to 0. We'll save that. Then we'll need to create a parameter and it's going to be a trigger. And that is going to be called start fading, hit Enter. And on the condition we are going to start fading when we do, we go to the next level. So now that we have everything set up, the next step is to actually trigger this parameter, and we'll do that in the next video using something very, very important called coroutines. I'll see you then.
31. Coroutines 101: Welcome back, my fellow game developers. In this video, we've suspended the time until we load the next scene. So as you can see, we have no longer blinking black images, only one black images that fades out. Then when we go to the next level, it fades and then fades back to transparent. How cool is that? Let me show you how that actually happens while looking at the scene. There you go. You can see when we go to the next level in here that it takes just a little bit of time. There you go. It is no longer instantaneous. It waits 1 second. It's a very cool way of doing things, so let's not waste anymore time. Let's get started. Oh, okay, So what we are going to do is we're going to access the animator on the image and we're going to start the animations from there. But we want a script. So which scripts should be controlling all of that? I think it should be the script on a canvas because we are going to use this Canvas for many things. And before I forget there, something that we need to do and that is in here in the canvas scaler. We need to scale with screen size. And we're going to set it to 1920 by 1080. So this is the ATP and this regular screens usually use to fit exactly with us right here so it doesn't change shapes as we move on. Let's continue on. Now we are going to create a new script in here. So a new C-sharp script is going to be the menu manager. Let's wait for it to compile and we are going to give it to the canvas. So now in the Canvas, Let's close all of this down. We have the menu manager, not level manager. Let's go ahead and open this up. Now. First thing we need is a reference to the image. So we're going to create a serialized field of type image. But unfortunately, we cannot use the image unless we said the Unity engine dot UI. So now we will have the ability to create an image variable. I hope that wasn't too fast. Next thing we're going do is we'll call this D image to fate in here. Now, what we're going to do is we're going to actually access the component that is on the image. And for that, I'm going to issue you a challenge. And your challenge is going to be to get the animator component. So create a method fade image acts as the animator component on that image. Set the trigger to start fading. And I'll give you a couple of hands if you want to do the challenge on your own and you don't need any help. Pause the video right now and go to the challenge. If not. Okay, Welcome back. So let's go ahead and create the method in here. I don't think we'll need the start and update for now, just for now, if we ever do need them, we will create them. So we're going to create a public void fade image. And in here, we already have the access to the image fate. We are going to get the component, which is the animator. And that is the component on the image to fade. And then we are going to set the trigger. Now. We are going to add a little point right here and we're going to set trigger. And because we need a string reference, we always need to go and copy it. So choose the image, go to animator, start fading. Copy that. Back in here, we pasted and we save it. So now the next challenge is, where should we be calling this faith image? Well, where do we want to call it? I think the best place to call it is in the area exit well, is the place that we need to call it. So in area exit, when the player enters, we said the transition, we start loading the next scene. But before we do that, we're going to go ahead and call the menu manager dot instance. Okay, we don't have an instance, so let's go ahead and create an instance. So as you're going to be a public static if you still remember how we create instances. So public static type menu manager, and it's going to be the instance, instance. That's how you write instance. And because we've deleted the start. We'll create the start again. See how easy that was. Instance equals this. And I don't think we'll need to make it a singleton pattern just for now. Later on we might need to. So now back in the area, exit will set the instance that fate mH. So now whenever our player enters the collider and we make sure it's a player. We add the transition name. We start fading the image and then reload the next scene. We'll save that back in our game. Let's run and there is a slight problem that you'll notice that our image fades but it keeps failing and you can see it right here. What's the problem? If we click on it? If we go to the actual animation in here on the fates thought, you'll notice that it has a loop time. So we'll just uncheck this box, click on Default and uncheck this box also. So now we save that. We run our game and we fade only once. Great. So now if we walk, there is a problem which is that we haven't. If we double-click on here and we need to start fading, but we don't have a reference to the image. That's because in level, where is it in the Canvas? Okay, in the Canvas, There you go. We didn't assign the right image. Now when we save it, now when we run, everything should be working fine. So we fade in. We walked to the next level, and there you go. We jump immediately to the next level. What's the problem here? Well, again, we haven't the prefabbed the canvas. So I'm taking you step-by-step very hard through this, but no worries. It's a good thing to learn from our mistakes back in here. Whereas our prefab, our Canvas, There we go, we save that. Let's try this one more time. And they're still a small trick that is not working. But now we fade in. We walk, and there you go. We fade into the next level. But there is still a slight problem if you've noticed that we are moving instantaneously to the next level, we are seeing even the fading out and our gain. So when we can, what I mean is we fade in. We want to have just a second just for everything to fade to black again. And that's not happening because we are immediately snapping. How can we fix this? We want a way to just wait a couple of seconds, maybe 1 second, just to fade out and then fade in the next level, like magic. The way we do that is using cold things. So what is a quality? It's a method that can suspend the execution of instructions until a certain condition is met. These suspensions are known as yield. And our example will be suspending the time until we load the next scene to see our, this should be our image to fade. Coroutines. Just take a moment to read about them. You can search them. The unity dogs, I do recommend they are a bit complicated when you first start doing them, but I will try to take you step-by-step and make everything easier. So let's not talk about coroutines. Let's go ahead and create them. So where should we be creating them? It should be where is it? In the area, exit. Area, exit. Instead of immediately loading the scene when the player hits, we are going to use a Goldie. So a coroutine is of type eye enumerator. So I enumerator, we're going to call the load scene Goldstein. And in here we are going to do a couple of things. So as soon as we enter what you can see that we have a squiggly line because we need to have a return value on it. So what we'll do is we'll yield, as I've told you, we need to yield, will need to return new. And we have a couple of conditions that we can use. One of them is wait four seconds. And now what we can do is give it a certain amount of time that it needs to wait before it does everything under and what does it want to do? Well, it wants to go ahead and use the scene manager to load the scene. And to call this co-routine, we are going to say start coroutine, load, seen co-routine. So what happens now? We start off, our player enters, we make sure it's a player. We set the transition, we fade the image, we start a cold in. All of this happens almost at the same time. But when we start a courting, this is where the magic happens. We enter the method. It's an eye enumerator. It's expecting a yield return. So it starts with this line. It reads yield return, new, wait four seconds. So it knows that it has to wait 1 second before it executes everything else. Let's see that in action, if you are a bit confused, pause the video, look at this, make sure you fully understand what's going on. And let's go ahead and test this out. So we run our game. Let's look at the animator. We walk, we fade out. We fade in the next level. How cool is that? So I hope you enjoyed if you are still confused about co-routine, I recommend that shoe again. Take a look at the code for you, then breathe out. Think about what's happening. Understand how yield works, how we're waiting a second before we load the scene and how the image is fading out and fading in. From here using our cold, I hope you enjoy it. And it's, this is a 10 heck of a long video, but it's very important. I'll see you in the next one.
32. Section 5: Creating Dialog UI: Welcome back my fellow game developers into this long, long video. But very important, as you can see, we've created some UI elements. We've added a text box right here, which is a panel. We've added a small name box in here, and we've also added a small character, which is a healer who is going to be able to talk to us. So hey Hitler, what do you have for us? So let's not waste any more time. This video is very long, and we also created our own font if you've noticed, and let's get started. Oh, okay, so creating dialogue, the first thing we need to do as we actually need to have an MPC to talk to. So we're going to add one of the MPC's that I've provided you with. And again, all of these are available on open game art so you find yourself watch ever you want. So this is the RPGs pride swan. I found it on. Maybe you can search it and find it yourself. And let's go ahead and use the, you can use whichever you want. Let's use the healer. So in these primates, that's change in here to the environment. So environment, and we'll add These two to the environment. And we'll create another file for the characters, and we'll add the walking demon and the healer. Let's get the healer. So here, let's double-click on the healer. There you go. He's not an excellent quality, but he'll do for now. We'll set it multiple, will make it no filter. Hopefully this makes the butt butter. So as you can see, let's go ahead and slice it up by cell size. No, that's too big. So let's make it 32, slice it up. Maybe we need to make it 32 on both ends. And nope, let's see how big it actually has to be. So it has to be 32 by 37. So let's try that. 32 with a width of 32, a height of 37. Slice it up. And I guess we need to have a bit of, let's say just like that or you know what, We can just slice this pride that we need. So we'll need only this one. So let me just delete the existing. And I'll just slice this one single sprite that we need. And there you go, apply and will only need this one sprite. We won't be having the player walking around. And let's get, whereas the healer that is just standing there you go, Here he is. So we'll drag him in here into our game that set the sorting layer as the player. And we'll put it as one. So not working. Why is that? Oh, it is working but he's just so freaking tiny. So let's make it four by four. And I think this is a good enough size. So now we have the healer standing right here. And next thing we're going to do is we're going to, let's change this to the shop or what should we call him the here. Okay, here we are. Then, there you go. This is our healer. Not sure who I made it capitalised. There you go, healer. So now when we run our game, we go towards our healer. Hey there healer. And we need to make sure that we can actually render over. No worries about that. What is it? The 0, the player is the 0. So let's make it minus one. Okay, great, Let's save that. The next thing we're going to do is we'll go into the Canvas. So double-click on the Canvas will open up the canvas, the swan. So we just see what's happening, the campus component on the Canvas. And we're going to go ahead and right-click and create UI panel. So where is it, the panel? There you go. So this panel is where we are going to put our UI element and it's where we will have all of our dialogue. Now you'll notice that it's transparent. So if we click on the color and will increase the transparency to its fullest, then we are going to choose this panel, hit D or the rec tool up here and we're going to make it a bit smaller. So this is about where our dialogue is going to happen, maybe even a bit smaller. So there you go. Now, we don't want it to be completely white. We want to have some elements in it. So let's go to the file where I've provided you with some UI elements. And let us go into the where should we set them in the sprites create folder. You are. Elements. And let's just drag the panel for now. And maybe I think I will just, let's just drag the font right now also. So let's drag the font into the UI element, and maybe this one also. Just keep it in here. We'll use it later on. So you see, we have this image and this will be our panel. And I'm going to go ahead. If we click on the panel, you'll see that we have a source image will simply replace it with this banner. So there you go. Here is our panel. It looks much nicer. We can set it to its native size. You can see how it should be looking, but we will stretch it out to our content. We can do a lot of things in here to change it a bit. Maybe we can turn of the re-cast target because we don't need that to happen. The re-cast means that if we can or can't click on it. Okay with that none. Now the next step is to add a text box in it so where we can a text. First of all, we'll name this de dialogue panel. Dialogue panel. And we'll right-click. Go to UI and use the text, but not just the regular one, the text Mesh Pro. And it will ask you to import centrals, had import essentials. And you'll see why in just a minute. We are using the text Mesh Pro. We're using it because it allows us to add our own font. And if we look in the font right here, this is the medieval font and we should have probably extracted it. So let's do that. Let's remove it from here. And inside of the medieval party, let's extract the folder. Okay. There you go. And where we got our phones is from a website called duff font.com. And you can go and check out many, many fonts. So what I did is I just wrote medieval and got all of these options and chose to use the medieval party. Let's see if that even looks good. So back in our game, and here we have our text Mesh Pro. Let's go ahead and expand it to all of the sides. We have to do this manually and 0. Of course, if you don't want to be shrinking it like this, you can actually hold down Alt, press on one of the sides. And there you go. You can see that we can make it bigger and smaller. So hold down Alt and expanded. Okay, so how are we going to create our own font? If we go into the window text Mesh Pro font asset creator, it gives us the option to add a font. So we'll go into the medieval party, less drag it into the fonts in here and UI elements. And now we'll drag it in here into these source font file generate from Atlas. Save that. It will ask us where do we want to save it? We'll save it inside of the UI elements font. Save that. So now we can drag the medieval in here. And we can write, for example, Hey, hey there, how are you? And we'll change the color to black. And there you can see that we have, hey, how are you? Let's tweak it a little bit, maybe make it bold. We can increase the font size if it doesn't look very good. And we can even change the distance between each letter. So we have the spacing option. See that we can separate them or we can separate just the distance between the words, which is very cool and all of this because we are using the text Mesh Pro. So maybe I think I'll just make it a little bit or we can make it auto size. So the more words we have less space it takes, we can change from overflow to all different things. We can set them in the middle and make sure it's in the middle, vertically and horizontally and so on. We can even add some lighting and the gloat width are all, all of these are options that you can try to figure out, see what happens. So if we add an underlay, you can see that we have a bit of a filling. We can increase the underlays. There you go. You can see that it's much, much clearer or we can change it to red, but we don't want that. Let's keep it as black, completely black. Okay, great. Was that done? Let me just reset this and maybe just maybe 0 or will keep the auto size. Let's increase it. You can see that we can set the minimum and maximum. So this is just a quick overview of how text Mesh Pro works and so on. Okay, great. So the next thing to do now that we have set up our dialogue panel is that we want to go ahead and set a name. So whenever we are talking to someone, we know that he has a certain name. And that's going to be part of your challenge. Your challenge is to create a name box. So create a smaller box or a smaller Name Box right about the big dialog box. I'll give you a small hint on how you can do this quickly. Simply duplicated and set the text name correctly. So you'll need to duplicate the panel, make it just a little bit smaller above the back panel. And that's it. Pause the video right now and go do the challenge. Oh, okay, Welcome back. So let's get into the text and here is a small introduction or a small lesson on how anchors work. I'll show you because I'm not sure how to explain it in words. So if we choose the dialogue panel, you can see that when we make it smaller, that detects goes outside. That's because the anchor of the text is in the middle. If we anchored to the top right, you'll notice that now when we make our dialog box smaller, the words stay inside. So this is one of the key aspects of using anchors and it's very important to understand how they operate. Let's make this just a little bit bigger on the side and on the side. And we can also go ahead and expand the text so it fills the entire square. But as you can see, we no longer see the side. So I think keeping it right here will be good enough for us. So let's fill up the whitespace with our text. And there you go. I think this is good enough. So now, in order to create the name panel, will duplicate the panel. We'll call it the name panel, main panel. And we're going to make it a lot smaller. So let me move this up a bit so you can see the text on the name panel should also be smaller. And let's just put it up here. Let's make it way, way smaller. So this is the size that it should be. And the text should also be much, much smaller. So this is the benefit of using Autopilot, but clearly the text is no longer readable. So let me just, just a little bit and we are going to change from the 16 by 9 aspect to the 1920 times 1080. And if you don't have it, you can add it using this plus. So 1080. Let's hit that. And now you can see that our tax is just a little bit more clear. So let me zoom out and adjust everything. And it's going to be your challenge to set it up the way you want it. So now let me just adjust the position and there you go. That's all that we need to do. As you can see, we've created a name panel, a dialogue panel. They adjust the size of the taxed accordingly. We've also created our own font. All we need to do right now is to commit our changes. So for I like to show that from time to time. So we are going to stage everything. We are going to call this, added a dialog box, commit the changes. Let us look at our master branch, and there you go. How amazing is that? Finally, we are seeing our game being built in front of our eyes. Look how much we've already covered. So in the next video, we are going to actually be controlling what happens inside of these two boxes. I'll see you then.
33. Dialog Controller (Arrays): Welcome back my fellow game developers. And in this video we'll learn about arrays. We'll learn about using text Mesh Pro. And I also make a huge mistake. So before we continue on, this is the code. Make sure that when I tell you that it's just text Mesh pro, that you use text much pro UI GUI. So with that all said, that's not waste any more time. And let's get started. Oh, okay, so what we want is we want to create a way to control our dialogue. So for that, I think it's only fitting if we create a dialogue controller. So let's just add the name panel to the dialogue panel. So we only have one dialogue panel. And let's go into the where is it, where r, that's close everything up because it's starting to get confusing and make the same but bigger. And this a bit smaller, just set everything up correctly. There we go. Let's right-click and go ahead and create a C-sharp script called the dialogue controller. And I think we have to start creating, Okay, what happened? Start to creating folders in here. So we'll create a folder column, the level management, and let's go and set the area exit, area, enter. Please stop doing that area. Enter the the level manager. Come on. Visual Studio. Open up. Yep. Now I know your tactics and what else should we choose? Maybe the camera controller. I'm not sure what also add, but for now let's just keep it so we will continue organizing our files. Let's drag the dialogue controller on the canvas. So now we have a menu manager and a dialogue Controller. And let's open up this script. First of all, because we are going to be manipulating and controlling UI elements, we will need the Unity engine wi, and now we need a couple of references. So the first reference is going to be a serialized field, is going to be a text Mesh Pro. But unfortunately we can't use texts much Pro unless we using Unity engine dot text, the BI Pro. And now we can start using text mesh per row. And there's going to be first of all, the dialogue text and the name text. So because we have two texts, if you remember the dialogue text which is in here, and the name text up here. Next thing we need to do is we'll need to create a serialized field which will reference the dialog box and the name box so we can turn them on and off. They are game objects. So the dialog box and the name box. And finally, what we need to do is to create a serialized field, which is going to be a string, and it's going to be the dialogue lines. Now you might be thinking, well, usually dialogue lines are, as the name implies, many lines, it's not a dialogue line. They are many lines. So what can we do? Let's go ahead and duplicate make 15 of those. We also have to rename them to 1, 2, 3, etc. But what if you want to add another one? So we'll come into the dialogue controller, then another one. But you can now see how cumbersome this is going to be and not pleasant at all. But thankfully, C-sharp has something for us, and it's the arrays. So what are arrays? Arrays allow you to store multiple objects of the same type in a single variable. What do I mean by that? It's not technically a single variable, but a list of variables which is called an array. So we create an integer, which is, we've already covered. It's a type of variable, but instead of just naming it integer, we add these two brackets right here. So this tells C Sharp that we are using this as an array of integers. We have the name, we have the same naming convention as variables, and we can add inside of them these values. How does this work? First of all, we have the type, we have the name, and we have the values that we give to that array. And one thing to keep in mind, how we index these arrays, we go from 0 to 1, to 2 to 3, 0 is always the first index and it's very important that you remember this exact step. The first value in the array is always, always 0. So the four is in the 0, position 6 in the first or the one. 112713 and so on and so forth. We can create arrays as big as we want, of course, to some limits. So how are we going to implement arrays in our code? Instead of creating 17 dialogue lines valuables, we are going to create a single one, which is going to be an array. So now we have an array of dialogues and we are using them to create our dialogue system. And we also need to keep track of the current sentence. So we are going to create a, another serialized field. We don't have to create this as a serialized field, but we just want to make sure that everything is working. So it's going to be the current sentence in US. Hope that's how you write sentence. Okay, good. So now we have everything set up. The next step is to go into the dialogue text in the start dot txt. And it's going to be equal to the dialogue, the LOC lines. And actually let's change this from biolab lines to dialogue sentences. Double-click on here, Control R and K dialogue sentences. I think it fits small because we are using the current sentence. So current sentence, there you go. So when we start, whichever current sentence we've sent is going to be the dialogue or the texts that appears on the dialogue text. So great, let's go ahead and test this out by issuing you a challenge at a couple of lines. So at a couple of lines of dialogue to the dialogue controller, play around with the current sentence and make sure the lines are displayed in the dialog. So I'll give you the opportunity to explore how arrays look in the inspector by yourself. This is very fun and exciting and maybe a bit scary for some of you. Pause the video right now and go do the challenge. Oh, okay, welcome back. I hope you did the challenge and I hope you realize that you needed to add the texts right here. So first thing we do, we go to the Canvas. Let's just click on this little lock right here. And this will enable us to choose whichever object we want without changing the inspector. A very handy tool, which I should have told you about before we did the challenge. I hope you're not mad. Anyways, dialogue text, we drag the text under the dialogue. There you go. It's not allowing me because so what did we name? Dialog box? Maybe it should be the text Mesh pro GUI. Yes, I think this is how it should have been from the start. So now when we didn't want to prove up that, sorry, let me just fix my mistakes quickly. And now, there you go. We can add the dialog box. Now, I realize how this must have been. You must have been very angry at me. So sorry for that. Again, we add the name. I'm sweating. So dialog panel and the name panel. Great. Now let's go ahead and add a couple of sentences. So you can see right now that we start with 0 sentences. Let's add one. Hey, there. I'm Jimmy. I come from the underworld. I used to kill many peasants, like you back in my days. But now I'm a good kind of demon if that even exists. So let's choose the current sentence and as you can see, the elements start at 0. So we'll choose element to one. Save that. Let's run our game. And you can see that I'm Jimmy. Very nice. Let's try the current sentence to change it. Let's try to use the element 3. Save that, run our game. And I used to kill many peasants like you back in my days. So that looks good enough. If you feel that the font is maybe a bit off, I recommend that you go find another font or you can play around with the text Mesh prop. So again, solving for not using the correct variable name in here, it should have been backslash pro GUI. If you did encounter this and you changed it on your own, then I just want to give you a hand of applause. You are amazing, so I hope you enjoy it. In the next video, we'll be reading multiple lines. So I'll see you then and I'll commit my changes.
34. Array Properties: Welcome back, My favorite game developers. In this video, we are going to be controlling our text dialogue using our leftmost button. So I'm Jimmy, come from the underworld are used to kill many peasants like you back in the days, back in my days. But now I'm a good kind of demons. And when we hit the last sentence, there you go. You can see that the text dialogue and disappears on its own. So let's not waste any more time and let's get started. Oh, case. So now we need a way to control our dialogue and go from sentence to sentence without actually having to put them every time manually in here. But when we press a certain button, either on the screen or some kind of button that we create in here. So let's get started. First of all, let's go into our dialogue controller. And in here in the update, we are going to make sure that we update this every frame. So before we do anything, we need to make sure that the dialog box is open in the hierarchy and the way we check it, and here you go. You can see it's active in hierarchy, that means defines whether the game object is active and deceit. And if you forgot what the hierarchy is there, it is, The name is up here. So if is active or active and hierarchy, then we will see what we want to do. What do we want to do? We want to take a certain input. So as I've said, we can either use this or we can create a button in here if you don't want to, just continue on. So if we press a certain button, so we're going to use input dot get button up. And if we look closely at returns true, the first frame the user releases the virtual button. Why are we using this one? If we look back here in the Unity documentation, you can see it's true and the virtual button is up. We don't want the player to start clicking on something. And if we use the get button down, for example, that will not work. Using the get buttoned up is a much better way, especially when it comes to handling dialogue, because it will avoid sometimes the player skipping through them or hitting too much. Anyways, let's continue on. Which button should we be using? Well, we can go into the input right here. So in the Edit Project Settings, Input Manager, but do we have options? Options, we have the fire one. So fire one is with the mouse 0, and I think it's the left mouse button, which I believe is the best option to use. So let's copy, fire one, close that back in here, paste it in here. And now what do we want to be doing? So the first thing we want to do is we want to take our current sentence and we want to increase it by one. How do we do that? We can say that the current sentence becomes the current sentence plus one. So what happens is let's say we are, current sentence is 0. We take 0, we added to one, and then we give this entire value and set it inside of the current sentence. So this becomes one. Then again, when we press again, will become the current sentence is one. 12, we give it to the current sentence. And next we take the dialogue text dot txt. And it's going to be the same as in here, which is equal to the dialogue sentences at the current sentence. But before we move on, this is a bit cumbersome to write and not very professional. And another way of writing this is by removing this whole line and then simply adding the plus behind it. So this will work the same way. But even there is a much better way of doing this. And whenever we want to add a 1, 2, any integer, we can simply write current sentence plus, plus. And this will add one to the current sentence whenever we fire or click the button, fire one. And whenever the dialog box is active in the hierarchy. And let's save that. Let's go ahead and test this out in Unity. So when we set the current sentence to be 0, we'll hit Enter. Let's see what happens. So hey, there. I'm Jimmy. I come from the underworld. I used to kill many peasants like you back in my days. Now, I'm a good kind of demon. Very nice. But what is happening in here? There is some kind of error. And you notice that it increases every time we click on the left mouse button or the mouse 0. And it's telling us that the index is out of range. Index was outside the bounds of the array. Hmm. Interesting, Let's double-click and see where the problem is. So there you go. The problem is in here. We are trying to add the current sentence. If we look in here, the current sentence is 20, while we have only one to five elements, so we are outside the bounds of our array. And this is a very common error to happen, especially when we are using array. So we always need to find a way to make sure that we never go outside the bounds of the array. How are we going to do this? Well, I'm going to issue you a challenge and you are going to fix it because I'm too tired. So create an if statement to check if the current sentence or the current number has exceeded the length of the array, if it has, turn off the dialog box, I'll give you a small hint. Use the dialogue sentences dot length to get the entire length of our dialogue sentences and use the dialog box dot set active to false. So with all of those hints, pause the video right now. This is maybe just a little bit of a tougher challenge for you because you need to compare the size of the dialogue sentences length with the current sentence. We can use these smaller and bigger sizes. So pause the video right now and go do the challenge. Oh, okay, welcome back. So in here we are increasing the size or the number of our current sentence. So before we actually give it in here, we need to create the if statement. And knowing where to set the if statement was also part of the challenge. So if the current sentence is greater than or equal to the dialogue sentences dot length. Then what we'll do is simply will go to the dialog box and we'll set it to false. Or sorry, I meant dialog box Lot set active to false. So what happens in here? Let's say we get to the current sentence number 5 or whichever one before. So let's say we get to four. And the length of the dialogue sentence is five because we have 01234. Then if the current sentence is greater than or equal to the dialogue sentence length, we are going to set the dialogue active to false. And how does this help? Well, if it's set to false, then an update, we can no longer enter this if condition because it's no longer active and the hierarchy, Let's test this out and see if it works. But before we do that, we also need to add an else statement to avoid the error. So we'll just move this up by holding down Alt and using the arrow keys and hitting tab. So it is on the same indentation. We'll save all of that. We'll go back into Unity. We will run the code. So now, hey there, that current sentence is at one. You can keep track of it right here in the inspector. I'm Jimmy. I come from the underworld. I used to kill many peasants, but now I'm a good kind of demons. So now when we go to the fifth or the current sentence becomes five. There you go. We have first of all, no error. And second of all, the dialog box just disappears. And even if we continue on pressing the current sentence is always five. So we've avoided a major, major error with just a couple of lines of code. So I hope you enjoyed the challenge. I hope it wasn't too hard. And I'll see you in the next video.
35. Activating Dialogue In Area: Welcome back, my fellow game developers. In this video, we've actually enhanced our system so we no longer just hit everywhere and everything should work. We only want the dialogue to activate when we are in the vicinity of our NPC or the MPC that can actually talk to us. So now if we are close to the MPC and we had the fire button, we can see that hey, we can activate the dialog box. We hit it multiple times. There you go. You can see that we activated. But if we are standing outside, you can see that there is no printing of the dialog box. We cannot open it. Again. There you can see inside of the triggers on we can, outside, we can. So let's not waste any more time and let's get started. Okay, so we already have created a sort of a dialogue system, but we don't want it to always be in here and always be controlled everywhere, wherever our gym edema and walks. We only want to trigger it whenever we are in the vicinity of one of the MPC's that we can actually talk to. So for that, we're going to go into the healer, will change it to healer NPC. We'll save that and we are going to add toolbox colliders to it. So the first box collider is going to be as the size of our MPC in here. This is 40 player bump into him and not walk over him. And we'll create a second box collider. And this box collider will represent the zone where we can talk to our MPC. So we'll create a kind of a big zone in here for our demon to fit in. So now you can see that in this song, whenever we enter it, we will be able to initiate a dialogue and we need to make sure that it is a trigger so we can use the entrepreneur anther and the, your player, the one you are using can actually enter into the zone. So I changed this to MPC. Okay, Thank you. The next thing we want to do is we want to create a script handler or a dialogue handler to add it to our MPC that handles all the dialogue to this specific NPC. So to do that, we're going to right-click and here we'll create a folder. It's going to be for the dialogue. We will add the dialogue controller script into it. And we are going to go ahead and create a new C-sharp script. The dialogue handler. Wait for that to compile. And okay, so let's add it to the healer MPC. There you go. You can see that we have the box colliders sprite renderer, the second box collider, and the dialogue handler. Let's open this up. Now. What are we going to do in here? So this is where we will keep track of all of our dialogues and then we will contact the dialogue controller where z. So let's open up the script. We will contact the dialogue dialogue controller and tell it which dialogue sentences we need to be using. So for that we will need access to the dialogue controller. And for that we are going to need a instance. So I'm going to issue you a challenge. And that challenge is to create an instance. So create an instance of the class dialogue controller. If you already know how to do that, pause the video right now and go to the challenge. If not, I'll give you a couple of hints. You'll need to create a public static variable of type and dialogue controller called instance, and then set the instance to this. So pause the video right now and go do the challenge. Okay, welcome back. So we've done this before. It's pretty basic and easy. It's a public static dialogue controller named in stance. And then start, we are going to set the instance to be equal to true. There you go. So I mean that, I mean true, I meant to say this. Okay, great. So next step is we're going to go into the handler and create two variables in here. So the first variable is going to be a public string, and it's going to be the sentences. And the second one is a private boolean that can activate box. So why are we creating the can activate box? What I mean by this variable, this Boolean variable is that whenever we are inside of the trigger zone on the MPC where Z told us way. Whenever we are inside of the trigger zone, we can activate the box. If we are outside of it, we can activate the box. So we're going to create two methods in here, which are the On Trigger, Enter 2D. And the arm triggers exit 2D. So how do these two methods work? The Trigger Enter, we've already used it on the area exit, but you haven't used the trigger exit yet. So you already know when we enter the certain area, the On Trigger enters, activates. But when we exit that trigger area, the On Trigger exit activates. Let me show you how that works. So inside of the entrepreneur Enter, we are going to check if the collision is compared to the layer. And even though this is a string reference, I'm pretty sure that's how you write player. And in here we're going to say can activate box is equal to true. So if we are inside of the trigger area in here for the MPC, then we can open the box. But if we are outside, we're just going to copy this. So if we exit the trigger area, we can activate box will be false. So only when we are inside of the trigger zone can we start and activate the dialog box? And finally, an update will create a condition if we can activate the box. And so remember this is the sign for. And so if we can activate the box and the input dot get button down on the fire one. Then we are simply going to go ahead and print out debug dot log. Hey, we can activate the dialog box. So we usually use the print to debug things, but print is something that actually prints out to the console while debug dot log is just for developing the game and doesn't print out actually something. So logs are better for developers and a much more professional way of doing things. So we'll save that. We'll go back into our game and then we are going to run our code. So now we can click on the button, will see that we have nothing in here. But when we enter the zone, you can see that fire one is unknown. Why is that? So far one is unknown. The problem is get key down. Okay, so let's get button down. Oh my God, get button down. And this should now work. So again, we run the code, we run our game. And now if we go to our MPC, when we had the fire one, there you go. Hey, we can activate the dialog box. You can see how many times it's being called right here on the right, because I've had the collapse removed the collapse. You will see that they are each printed on a single line with the collapsed. They are all concatenated. If I move out, you'll notice that if I hit the key there is no printing out of behavior. Can activate button. When we're inside. There you go. We can activate the button. Now in the next video, we will make this much more sophisticated and really implement this in our dialogue system. Was that done? I hope you enjoy it and I'll see you in the next video.
36. Dialog Handler : Welcome back, my fellow game developers. In this video, as you see, if we had the mouse button, nothing happens. If we go up to our healer and hit the mouse button, hey, I'm healer. Hey, I'm a daemon called the Jimmy. I have come for your soul. Why are you so mean Jimmy? You seem to be nice. And that's the whole conversation. So let's not waste any more time and let's get started. Okay, so now that we've set everything up, it's time to actually start activating the dialog box based on whether we are inside or outside the song. So the first thing we need to do is we will need to go to the dialogue controller and create a method in here that will activate the dialogue. So it's going to be a public void. Activate dialogue. So this will initiate the dialogue and we are going to pass it an argument. And this argument is going to be the string array of the new sentences to use. So this obviously will be handled in the dialogue handler, but we'll deal with that later on, explain it more. So the dialogue sentences, the ones that are on the dialogue controller, will be equal to the new sentences to use. And because we are starting off the conversation, the current sentence will be equal to 0. So this is the variable that keeps track of which sentence we're on. It's going to be 0. And the dialogue text dot text will be equal to the dialogue sentences, the sentences on the current sentence. So this is just to initiate everything. And finally, we need to also activate the dialog box. So dialog box dot set active to true. And we are of course going to deactivated in here on our player. So where is it? Where is our Canvas dialogue panel? And we'll turn this off. And in Canvas this is the dialogue panel. It will be turned on later on. So save all of that. And now I'm going to issue you a challenge. And your challenge is to activate the dialogue. So activate the dialogue from the dialogue handler script. Use the instance of dialogue controller and make sure to pass these sentences to the method through the parameter. And we've already established where in the dialogue handler you should be calling the dialogue controller method to activate the dialogue. So with that said, pause the video right now and go do the challenge. Okay, welcome back. I hope you knew how to do that. So in the dialogue handler, when we press the fire one key and we can activate the box, we are going to call the dialogue controller dot instance dot activate dialogue. And we are going to pass him the sentences that we have. So the sentences save that. Now we'll go back into Unity and even we can go to the dialogue controller and we'll set this letter onto private. But for now, whereas it, I'm going to set this to private. We can have even said the current sentence to private, but we just want to make sure that everything is working. So on the NPC healer, we have the sentences that we want to add. So there you go. We can say, hey, I mean healer. So this is a conversation, Hey, I'm a daemon called or know what? I'm a daemon called. Jimmy. I've come for your soul. Why are you so mean Jimmy? You seem to be nice. Okay, so this is a small conversation between Jimmy and the healer. So what will happen now is we are going to run the code. So this is the script on the dialogue handler of the NPC. And on the canvas we should see that, hey Jimmy, we, everything is still the same. But when we walk up to the healer, when we had the fire key, there you go. Hey, I'm a healer. Hey, I'm a daemon. So you can see that there is still a small problem. We are not changing. We are going from sentence 0 to sentence one. So what's the problem in here? Well, the problem. That in the dialogue handler, we are updating each frame, checking for if the box can activate and if we are hitting the fire button. So what's happening is that this method is being called every single time. And what that does is it goes ahead and activates dialog box and again sets the current sentence to 0. So we need to make sure that we call upon it only once. How do we do that? We're going to add another condition in here. So if the box is active and we press the button key and the dialogue handler. So you'll notice I've added an exclamation mark. I'll tell you what that is. And the dialogue handler or dialogue controller, dot instance, dot dialogue box. So dialog box is, where is it? The dialog box is a serialized field. We cannot access it. We can do two things in here. So we can either turn this to public and give everyone access to it. Or a much more sophisticated way is to go ahead and create a public boolean. And is dialogue active. And what this does is it will return, return dialog box dot is active or active in hierarchy. So now, if the dialog box is active and hierarchy, this will be equal to true and we will return the value. So if dialog controller dot instance dot is dialogue, is dialogue. This should have been maybe dialog box active. So dialogue that may change the name dialog box active. Apply that. What's the problem? Is dialogue box active? There you go. But what about this little exclamation mark? So what's the point in here? What are we actually doing? We want to make sure that if the dialog box has been already opened, we don't want to keep calling the activate dialogue. So this little exclamation mark tells us that if the dialog box is active is true, the exclamation mark reverses. The dialog box is active. So if this whole sentence is true, this whole condition in here is true by adding an exclamation mark, we turn this into a false. So what happens in here? We check boxes active. We had the fire key, the dialog box is active, but because of this exclamation mark, this makes this whole condition false so we don't activate the dialog box. How cool is that? So take a bit of time if you are still confused, what's happening? This exclamation mark, inverses deconditioned and mix it all falls or makes it all true. So with that said, we will save this. We will go back into Unity and we will try this again. So we'll run the code, we'll go up to the MPC, will hit. And there you go. I'm a daemon called Jimmy. I have come for your soul. I Why are you so mean Jimmy? You seem to be nice and we finished the conversation. Okay, great. But if you've noticed there is something wrong happening. So again, if I go into the healer, hit the key so high I'm a daemon. So where is the, hey, I'm a healer. It's not showing. That's because if we go back to our dialogue controller in here, we can see that whenever we hit the button, we immediately add the current sentence. So how are we going to fix this? Well, it's fairly easy. We'll just create a variable in here that will keep track if the dialogue just taught. So a private boolean dialogue just started. And in the activate dialogue. And here we are going to dialogue just started equals true, save that. And whenever we hit the fire key, we were going to add another condition in here. So if the dialogue just started, or what I meant to say is that if the dialogue hasn't just started, then we are going to add a plus two it else. We are simply going to set the dialogue just started to false. Okay, so let's test this out and I'll explain a bit more. So now we run our game. We go up to the healer, we initiate the conversation and as you can see, we haven't skipped over the first line, and then we continue on with our conversation. So what's happening in here is that we've created a variable. And as you can see, I've added an exclamation mark. So if the dialogue just started, we do not enter into this condition. We set it to false, and we actually initiate the first line of code in here because we've added. So what was happening is that we said the dialogue tax to have the current sentence which was 0. But as soon as we hit the fire button, again, we have a current plus plus and we are changing it. So this will allow us to, first of all, if it hasn't just started, then we will add a plus, plus. But if it has just started right now, we will not increase the current sentence. So I hope that wasn't too confusing. It's just a way to mitigate damage whenever we are starting a conversation. But there are still two problems in here. The first one is that when we go up to our lady in here, if we are talking to her, we can still walk away. And as you can see, we are talking to her from another map almost. And that is a big no-no. We need to find a way to stop our Demon from moving. The second one is we are talking, but we don't know who is saying, Hey, I'm a demon, may be freezed. The daemon called the gym. Maybe she's called the gym. We don't know who's talking, so we need to add a name in here, but that is for another video. Until then, make sure to commit your changes. And I'll see you in the next video.
37. Holding Player Movement: Welcome back, My favorite game developers. In this video we've thought, or demons some manners. So now when we go up to speak to the nice healer lady, we can no longer run away from her and shout from the other side of the screen. So unless we finished the conversation, we have no way of leaving. So as you can see, when we do finish the conversation, we can leave and go have a swim and the waters. So let's not waste any more time and let's get started. Okay, so as we've covered in a previous video, we want our player to stop moving whenever we are having a conversation with the NPC because that's good manners and our Timmy demon needs to have good manners. He doesn't have good conversation skills, but he has manners. So how are we going to do this? We are going to have to find a way in the player to activate the movement whenever we are talking and we are handling it in here and the velocity. So the way we stop this is by issuing you a challenge, so you are going to stop the player from moving. So create a Boolean variable and declares a script, which will be the activate movement or you can call it whatever name you want. An update. Check if the variable is true and we will set it to a velocity of 0. So if the variable, the activate movement is true, the velocity of the player should be set to 0. Else will simply keep the velocity as it is. So pause the video right now. Take the time to do this challenge. It's very important and I'll see you in just a bit. Oh, okay, welcome back. So the first thing we need to do as a public boolean deactivate movement is equal to false. We'll make sure that we start off by having the activate movement false. And in here, when we set the floats for the get axes horizontal and vertical, we're going to check if the deactivate movement is true. Then we are going to go ahead and access the players rigid body. We are going to access the velocity on it. And in order to set it to true, we're not just gonna say that it's equal to 0. We are going to make sure that we tell it that it's a vector two dot 0. Why are we using this instead of just a 0? Because you can see that the velocity in here, you can read that it's a vector, too rigid body velocity. And to set it to 0, we need to use the factor to the 0, which is initially just a 0, F 0, F vector. So what next should we be doing? Well, we need to add an else case and then set it right here. So if the deactivate player movement is true, then the velocity becomes 0. Else, we just set it as the normal velocity. So let's test this out and our gain. Oh, we haven't actually activated this. So in order to make sure we do, we need to go into the dialogue handler. I mean, the, sorry, the dialogue controllers. So in here, the dialogue just activated and we need to go and to the player dot instance dot the activate movement. And we will set it to true. Now, obviously it would have been better to make this a private variable and create a method to access it. But for the sake of moving faster, we will use the instance. So we'll say that back in our game, we run our game. Jimmy goes up to the NPC, Hey, I'm a healer demon. And now we cannot move any longer. Even though we stop, the conversation will need to deactivate the deactivate movements. So now we can move, but as soon as we start conversating, we can not move. But there is a slight problem and that is that we can still look around. Now if you want, this is a cool feature. We can keep it, but we don't want to in our case right now. So I'm going to show you a mini challenge for you to stop the rotation of the player whilst we are talking. So this is not an official challenge. Take a moment, pause the video. Do it yourself. Time's up. So Let's go ahead. If we are not the activating the movement, then we can set the animator. So because our turning is handled right here. So if the movement is equal to one and so on, we are accessing the animator. We are setting the last x, so we have the activated movement set to true, then this condition is not going to work and we will not set any less tax, but that done, let's go back into Unity. Let's make sure that we save it. Nope, we didn't. So again, we need to just noticed I have a thing for the asterix at the top. So we go to the NPC, we start talking and there you go. We cannot turn around. So I'm trying to hit the WASD and nothing is working. Okay. But one final problem. How do we give the ability to Jimmy to start walking again? Well, we are going to go into the dialogue controller. And when we check if the current sentences are greater than the dialogue sentences length, we are going to set the dialogue active to false. And we are going to go and access the player dot instance, deactivate movement and set it to false. So we'll save that. Now, we should be able to see that Jimmy can walk again after he finishes having a conversation with the nice lady. So hey, I'm a healer demon. And there you go. We can walk again if we tried to walk around when we are talking. Yep, There we go. So now we have a very well mannered daemon. So make sure to commit your changes. And in the next video, we will handle the names of the characters speaking. I'll see you then.
38. Showing Characters Names: Welcome back, My favorite game developers. So now when we walk to our healer, we start talking. We know that it's a healer. So hey, I'm a healer. Jimmy. Hey, I'm a demon. Jimmy called Jimmy. So Jimmy is talking, he says, I'm called jimmy. I've come for your soul. Why are you so mean jimmy? Who's talking? Oh, it's the healer. Okay, great. So the healer says You seem to be nice. So Jimmy has proved that he has exceptional ways or with healers in the town. So let's not waste any more time and make sure that we know who is saying the dialogue centers. Oh, okay, so now we want to set the name of each character speaking. So there are many ways of doing this, but I believe the easiest way is the following. We'll go into the healer for example. And in here Let's say, hey, I'm a healer, but we'll do, is we'll set a certain character which can be anything. It can be the hashtag symbol. So whereas the hashtag symbol, so for example, the hashtag symbol healer. And what we'll do is we set it somewhere. So now the healer is speaking. Again when we want to make sure that it's the demon speaking, we'll set Jamie and here, okay, and let's do this again. So we'll click in here. And another one. Healer. Why are you so mean Jimmy? You seem to be nice. Okay, so now you can see that we have healer, Jimmy, healer talking. But how are we going to make sure that when the sentences are red, that we know that it's a healer. Well, we're going to use the symbol that we said behind it. And we are going to use two methods in C-Sharp. So the first one is string dot starts with, and this allows us to check if or determined whether the string instance starts with a specific character. This will allow us to check for the character or symbol that we had at the start of the sentence. And then we'll use Replace. And with this we will replace the symbol with some kind of maybe just an empty space, so we will get rid of it so it doesn't show up in our names. Let's go ahead and implement this. So an hour, whereas it and our dialogue controller will create a method and here that's called void. Check if name or check for name. Let's call it the check for name. I think it suits the method butter and it doesn't have to be public, it can be privately. I don't think we'll be using it outside of the dialogue controller. So we'll create an if condition in here that will check if the dialogue sentences at the current sentence dot starts with the Hugo. As soon as we write. I'm not sure how even Visual Studio can be so smart. So if it starts with the hashtag character, then what we'll do is name text. So we've already said the name taxed up there. Dot text will be equal to the dialogue sentences on the current sentence. And we are going to replace the hashtag with a, an empty space. Let's just replace it with an empty space. And then what we'll do is we'll increase the current sentence by one. Okay, so what are we doing in here? First of all, we are checking if the dialogue sentence at the current sentence starts with the hashtag or whichever symbol that you chose to add. We are going to access the name tax dot text and we'll set it as the dialogue sentence at the current one. But we will replace the hashtag with an empty space. So now we know that it's the name, but because we don't want the name to show up in the dialog box. We will increase the current sentence from here immediately and we will continue on with the conversation. So the final step is to know where to call the check number. And that's going to be part of your challenge. And your challenge is going to be to call the check for name method. So find the two. So there's two places where we should be checking if a sentence is a name or a line of dialogue, and apply them and run the code, run the game, make sure that it works. So pause the video right now and go finish up the dialogue end game system. Okay, welcome back. How did you get on with that? This was a very important challenge if you haven't tried to do it, do it right now, it will give you more insight on how games work and it really is a fun challenge to know where we should be calling. So I've gave away the spoiler. We need to check the name right before we activate the dialogue. So this is the first place. And we should always be checking if we're setting the dialogue text dot txt. So where else should we be checking? In here? We're going to check for name. So save that. I think these are the two places that we need to be checking. Let's try this and see if I was right. So we are going to run our game. We are going to walk up to the healer, will hit Print. So there you can see healer, Hey, I'm a healer. Jimmy, hey, I'm a daemon called jimmy, I've come for your soul, the healer. Why are you so mean Jimmy? Seem to be nice and there you go. We exit out. So how cool is that? Now we know who is talking when and where. So the dialogue is complete. I hope you enjoy it. I'll see you in the next video. And don't forget to commit all of your changes. We are doing amazing. Look how much we've already done. I'll see you next.
39. Section 6: Player Stats: Welcome back my fellow game developers. And in this video we are going to be creating a player stats. So if we click on the player right now, you'll see that he has a couple of stats and the max HP, the current HP TEDx dirty defense, and of course the name of Jimmy the demon. So let's not waste any more time and let's get started. Oh, okay, so it's time to create some stats for our player. And as we've talked about delegation before, we don't want our player script to be handling the player stats. We are going to create a different kind of script to handle that. So we're going to create a folder in here. We'll call it the, let's say the maybe characters will add the player script to it. And we're going to go ahead and create a player stats script. And here, so right-click, create C-sharp script and we'll call this D layer. Stats. Hit Enter. What should we be doing in here? Well, we are just going to set up a couple of stats to have for our player. So the first step is going to be a serialized field. It's a string, and it's going to be the player name. So that's the usual first step that we have for any kind of director in an RPG. And then the second variable is going to be the players level. Because as we know, every player in an RPG has some kind of level and we're going to set it at one by default, will be able to change all of these in the inspector because we're setting them IS serialized fields. We are going to keep track of the current XP. So the current XP, and let's just remove the equals in here. So current experience, what else do we have? Well, we have the max HP, so the max health, and we're going to set by default to 100. We have the current HP that we want to keep track of. So current HP, let's remove this gulf. We want to add magic to our player. We will also have a max Mano. So if you don't know what mana is the source of magic for any character, how much mana you have determines how many spells you can guess. And we'll just separate all of these with a space to keep everything neat. And of course we'll also have the current manner. So current Mano, what else should a character have? An RPG? I think dexterity and defense are a good stat to have. So dexterity and difference. And if you don't know what, I'm sure you know what defenses, but if you're not sure what dexterity is, dexterity is your ability to handle a weapon. So the more dexterity you have, the more you can handle a weapon. Electron will maybe add a couple of more things in here, like the equipped weapon and the equipped armor. But for now I think these are the basics that will work on. And when we need to add more, we'll just come back and add more. So let's save all of that. Now let's go back into Unity and where is our player? Let's drag the player stats onto the player. Let's minimize the animator. And there you go, you can see the player stats. So what should we do here? What's the name of our player as we've said it, Jimmy? And what's the current experience? While let's say we'll give him maybe 200 or not to a hundreds too much. Let's give him 36. With the Max HP is 100. We are going to give him a dexterity of 10 and a defense of, let's say 30. Okay, so these are just arbitrary numbers. You can add whatever you want later on we'll delve deeper, but for now, we just want to set the ground for everything and then start working up. Now, it's time to give you a challenge. And your challenge is going to be to create stats. So add your own player stats you'd like to have. As you saw, these are very basic, basic, basic. You can add a lot more. So if you've played a game like, let's say followup New Vegas, it has intelligence, luck and so on. Dark Souls, For example, also has a lot of, that's there. That's where I got dexterity. And we'll be using different RPGs to create a leveling system from them and how we attack using those systems. So here are a couple of examples. Speed, vitality, endurance, intelligence, lock, etc. So there are a lot of skills. As I've said, this game is your game you created as you'd like. Don't be afraid to add a couple of stats to experiment, to then adjust the code as we move on through our game to suit your stats, to suit your own needs. And that's the process of learning. Sitting here watching me do cold and not doing anything isn't going to help you as much. So with that said, pause the video right now at a couple of your own stats if you want. And I'll see you in the next one. And also if you are enjoying the course so far, it would help me out a lot if you leave me a positive review on the course. And thank you, I'll see you in the next video.
40. For Loops In Unity: Welcome back, My favorite game developers in this video, as you know, each game of RPG, each player in your game requires leveling up. So we've created an experience for each level. So the amount of experience for each level, and it's done dynamically. So as soon as we run the game, you'll see that from level 0 you are here. To get to the level two, you will need 100 experienced two, level three, 200, 300, 400, 56 until you get to 49 thousand or 4,900. So you can see that all of this was done automatically using loops. So let's not waste any more time. And let's get started. Oh, okay, so it's time to start leveling up our player. So to do that, we are going to go into the player stats and we are going to add two new variables in here. So first we'll add a serialized field. So serialized field, it's going to be an integer and it's going to be the max level, and we'll set it at 50. I don't think we'll need more than 50 max levels. You can change that based on the character that you have. You'll see that we can add this player's stat to any character and make them a player or a playable character. And the other variable that we want to add is a serialized field, which is going to be an integer or an array of integers. And it's going to be the experience that we need for each level to level up. So it's going to be the XP. For each level. There you go. So now we have the max level that our player can get to and the experience to get to each of those levels. Next thing we want to do, we want to set these experiences for each level. So how do we do that? First of all, and start, we are going to create the array of XP for each level, and this is how you create it. So the XP for each level is equal to a new array of integers. And we need to determine what size it's going to be and the size is going to be the max level. So now the number of experience for each level will be the max level. So how many levels do we have? Well, we have, for example here 50. So the size of the array XP for each level will be 50. Next thing we want to do is we want to be able to set up these experiences. To do that we need another variable and I'm not sure where we'll add the class. Just keep everything that is related to experience in the same block in here. And it's going to be an integer. And we are going to be calling a deep base level XP. So this will be equal to 100. So the first level is 100, and we'll set that also in here. So the experience for each level on the level one is going to be equal to the base level XP. Okay, great. Now an order to fill the rest, we are going to use a loop because we don't want to go. And for example, for each and the two equal to some kind of number, we want to do this dynamically. And fortunately, there is an amazing tool to do that which is called loops. Let me explain what loops are. So to be specific, what is a for loop? So loops can execute a block of code a number of times. Loops are handy if you want to run the same code over and over again each time with a different value. So this is the structure of the loop. We start off by writing for, and this is a for loop will see a different kind of loop later on in the course. So for example, we write four, we open up these two brackets. We start off by initializing the first condition. So int I equals 0. While I is less than a certain limit, we will increase I plus, plus. And each time we will execute the code which is between these two curly brackets. So we continue to execute this code inside until I reaches a certain limit. We start off at 0. Let's say the certain limit is three. We start off at 0, okay? We can execute the code. We increase i by one is I, which is now one, less than three. Nope. So again, we execute the code, we increase by one. I'm becomes too is I less than the certain limit? Yes, it is. Did I say no previously? So I equals two is less than the certain limit, which is three. Again, we execute. Finally we get to 3. So I equals three. Is it less than the certain limit with just three nodes not so we exit the loop and we finish off. Let's add this to our code and see what happens. So back in the start, we are going to create a for loop. So for will open up the brackets. We'll write int I equals to. And why are we not starting at 0? Think about it for a bit. Why are we not starting with I equals 0? Well, because we've already established the I equals one and here, and the I equals 0 will be, of course 0. It's the base level. It's what you start off with. To get to the first level, you use the base level and then we will set the rest from I equals 2. What is the limit that we don't want to exceed its the size of the array, which is the XP for each level. So we get the size using the length and will increase I by one each time. So now what are we going to do and here? Well, we're going to issue you a challenge. Actually, I'm going to show you a challenge and your challenge is to print number we are at. So use the print method to print out I or the number where we're currently at in the iteration. So pause the video right now and go do the challenge. Welcome back. So it's very easy. Simply write, print, open the parentheses. Let's go ahead. We are at and we concatenate a string, which is, we could have simply written I, but this is just for more aesthetic purposes. We'll save that back in Unity. And we, we, we added everything. So now let's look at the console. We've made sure that the max level is 50. You can see in here that each XP as at 0, but it's an array. So when we run the code, but there you go. You can see that now we have from 0 to 49, so 50 levels, the first one is 0, the second one is initialized at 100. And you can see the numbers in here in the console starting from 2, 3, 4, 7, 8, 9, 10, 11, 14. And they continue until they get to 49. Okay, Great. With that said, next, we need to do something real in here, not just print. So we'll comment this out. And we're going to go ahead and say that the XP for each level at the position I, because remember I is increasing with each iteration. So we are going through each element in the array of the XP for each level, and it's going to be equal to the base level XP. And we're just going to multiply it by I. Save that. Let's go back into Unity. Let's wait for this to compile and keep your eyes on the XP for each level, we will run our game and there you go. You can see that we start off in order to get to the next level, we need 100 XP to get to the next, next level, 200 to the third level, 300, 400, 56, and so on and so forth until we need 4,900. So with that done, I hope you enjoyed that. Just maybe one more time. Explain what's happening in the slope because if you are unfamiliar with loops and this is your first time, it's worth listening to it one more time. We start off. Our initial condition is two. We have a certain limit, which is the length of the for each level array which we've created in here. And each iteration we increase i by one. We've seen how this looks when we printed out the I on each line. Then we take this guy that is increasing every single time and we use it to go through the array and on each, and let's say element of the array, we are setting the base level speed times the number I. And this is how we increment each time assigned to all of the speeds for each level and the array. So I hope you enjoy it. And in the next video will be incrementing the speed to the next level and not as stable as now. So we don't want to have just 100 points differentiate between each one. As you know, the RPG games, each level requires more than the previous one to increase. So let's say the first level took us 100 experience, the second should take more than 100 to get over it. So I'll see you in the next one.
41. Experience Distribution: Welcome back, my fellow game developers. In this video, we are going to be implementing a different equation to get the experience that we need to get to each level. So when we run the code, you'll see that we no longer have a 100 each time, but we have a very well distributed level to get to the next level. So you can see, for example, it takes 223 to get to level two. But if we want to go from seven to eight, that requires a bit more and down the line, you'll notice that it also changes as we progress. So let's not waste any more time and let's see how we implement this distribution 0. So how are we going to distribute the experience that we have? Because as we've said previously, we don't want to just increase by 100 each level. We want to have something a bit more, let's say dynamic. So we want to be a bit harder every time. So what I've found is this really nice page, and this is from the Dark Souls wiki. If you're not familiar with Dark Souls, I do recommend you play it. It's an amazing game and really a great place to learn how RPGs operate. You can get a lot of information. So for example, what kinds of player stats you want. And in this particular page is the amount of experience required to go from one level to the next. So as you can see, the numbers don't increase normally. You can see, for example in here they increased by 13 and then some kind of number. I'm not going to do the math in here, but each, for example, level, you can see that there is a difference from the previous two levels. So to get, for example, from this level to this level, you can see that it requires around 300 maybe souls to get from 690 to 707. You can see that it's much less than a 100. So this is what we want to implement into our game. And thankfully, we have a little equation in here. So as you can see, y equals 0.2 x to the power 3, and x is the number of times. So how can I say it? So for example, each time this is the x, we start off as the base level and then we increase x and one and so forth. So in our code, the x is going to be the I, and we are going to try and apply this. So let's go back into our script and let's see how we can do this. So let's remove the printed here and let's start off again. So I have the formula in front of me and I recommend that you also get the formula somewhere next to you. So we're going to open up the brackets and we're going to write 0 to F. It's going to be times I, times I, times I. And why am I adding so many times I, because if we look back in here, you'll notice that it's 0.02 times x to the power three. And we can find power in Unity. Oops, we can find the power and unity, but I think that using just times times, times is a lot less complicated and easier and avoids a lot of mistakes. The next thing is 3.06 F times I times I, and that's it. So let's see again, there you go. Times 2, 3.06. Then we have 105.6 times x. So it's going to be 1.605 F times I. And there you go. Let's save. That will not be using the minus 895. I don't think it's that mandatory. Let's just keep it at what it is. But if you've written the equation, you'll notice that there is a small problem. There is a red squiggly line. So if we hover over it, you can see that float operator, float on the left error is cannot implicitly convert float to an integer. An explicit conversion exist. So what's the catchy, what's happening? So experience for each level is an array of integers o, k. But what we're feeding it is a value that is a float. So you can see when we write a float, so for example, 0 to F, That means this is a float and 3.016 or 3.06 F as a float. So how are we going to be able to feed a float number into an integer variable? Well, I'm too tired to do this, so I'm going to give it to you as a challenge. Convert a float to an integer. Let's say you are a game developer and you get to the point where you encounter a problem such as this, it's time to use your incredible ability of problem solving. So do a bit of research and look up how to convert a float and to an integer. There are two methods of doing this. You can go and look for these two methods on your own, or I'll give you one of them. I'll give you the hard one and it is math floor to and I'm not going to say more than that. Pause the video right now and go do the challenge. Oh, okay, welcome back. So what did you find, how to do it? So if we go in here, you can see that we have, we met, have floor to ENT. And you can use it to convert returns the largest integer, smaller or equal to f. So there you go. This is how you use it, Math.floor and you put the float and cite this for example, we'll print out 10. You can see the examples next to it. But we're going to use butter tool. And that tool is by simply writing and before it. So you can convert anything using this method right here, although I think it takes up more memory from the computer, but we will not worry about this. I'm sure that you have enough memory in your computer with that done, I hope you enjoyed and I hope you are committing the changes that you're making. And with that said, I'll see you in the next video where we'll be testing our leveling system. So see you then.
42. Testing Levelling: Welcome back, My favorite game developers. In this video, we've created a way to increase or to test our XP for next level by increasing the amount of experience. So as you can see right now, we are on level one. To get to level two, we need 100, so we press the L key. You can see that we got to play or level 2. Now we need to a 123. So there you go. To get to level 4, we need 344, so we keep increasing until we get to level 4. So let's not waste any more time and let's get started. Oh, so now we want to be testing our leveling system. And let's go into our script in here and the player stats. And we're going to create a new method. So this method is going to be a public void, add XP. And in here we are going to tell it the nth amount of XP. You can add the amount of XP to add, but for now, let's just keep it up. That next thing, what we're going to do is whenever we call this method, we are going to get our current XP and we're going to add to it the amount of expect to add. So we remember this plus equals from before. This is the same as saying the current x b is equal to the current speed plus the amount of XP. Okay, great. Now the next thing we want to do is after we've added the amount of XP, we want to check if the current is greater than the XP for each level on the player's level. Then we want to go ahead and first of all, remove from the current XP minus equal the XP for each level on the player's level. And then we will want to increment the player level by one. So there you go. Why are we removing and here the EXP? Because as you know, for example, let's say you've gathered 480 XP and you want to go to the next level. You don't just keep everything with you don't go to the next level which will, might require 600. So you don't keep with you the 480 and then only need 200. You will have to go back and or remove the already amount that you have. And we don't want to set it to 0. Because let's say for example, we want to give the choice to the player to level up or not, just like an Dark Souls. Maybe we don't want to make it mandatory, so we don't want to reset it to 0. We simply remove the amount of experience takes to go to the next level. So this is our method, that's all that we need to do. And I'm going to issue a challenge to call this method and update. So use the input from a key and update to add XP to your player. I recommend you pause the video right now and go do the challenge. Or you can see the hand that I'm about to provide you. We've already done this. Pause the video right now, go to the challenge. Or use the input dot, get keydown keycode, and use one of the keys. So pause the video right now and go do the challenge. Okay, welcome back. So an update. We are going to check for if the input dot get key down. And with a key code of, let's use L because it's the leveling up. And what we'll do is add XP and we'll add 100. So I guess I 100 is a good amount to add. Now before we move on, there's something that's bothering me. The name XP for each level. Isn't that good of a representation? It should be the exp E for next level. So XP for next level, it represents battle, what we mean by this array. So the XP to get to the next level is this. Okay, so back in Unity and let's go ahead and run the code. So you can see that the current is 36 and we need 100. So if we had the alkene, you'll notice that now we are on level two and here, and the XP is still 36. Why is that? Well, because we went from level 0 to level 1 and we remove the 100. So now if we had the LD one more time, There you go. We are still at level 2 because we require to a 123. Now we should go to level 3. Yep, there we go. Level three and I believe that we subtracted 223 from the number that we got. So that's why we're left with 13 again. So we need 344 to go to the next level. Now we go to for and with a 69 current XP. Very nice. Again, let's try to level up to level five, which requires 470 to 469. We just need a little bit more so we'll add a bit of XP. There you go. We are at level 5 with a current XP of 1970. So as you can see, our leveling up method works completely fine. So I hope you enjoy it and I'll see you in the next video where we will be actually impacting the stats that we have on the player after each level up.
43. Leveling Up The Stats: Welcome back, my fellow game developers. In this video, we will not only be increasing our level for the fun of it, we are also going to increase our stats as we increase in levels. So right now, you'll see that we are at level one hour max, HP is 100, maxmin of 30, dexterity 10 defense 30. And now I'm going to press L and you keep your eyes on the stats of our demon or player. So as you can see as we level up our dexterity, defense and Max HP increase in varying ways. So let's not waste any more time and let's implement these changes into our game. Oh, so as we know an RPG games, when our level increases, we need to have more strength, more ways to defend ourselves, more HP and more mana or the power of magic. So we are going to add this or integrate this into our leveling up. So let's go into our script and we open up in here. Where are we? Okay, so every time we increased the level, we're going to do something different. We want to increase the dexterity and the defense, but not every single time. We want to check if the player level that we are at currently is divisible by two. And what does this mean? Do you know the sign for modulo? Modulo this divides the player level by 2 and sees if there is any residual. So is there any other term? For example, if player level is 3 divided by 2 at leaves out one, so there is a another number. And when we divide, for example, an even number by 2, we have 0. So when a even level comes up, we are going to increase the dexterity by one. Else. If it's an odd level, then we are going to increase the difference by one. So each level we have either the dexterity or the defense getting increased by one. And what else can we add? First of all, let's go ahead and test this. We save it. Let's make sure we saved it back in Unity. Let's run our game so as you can see, our dexterity and defense or 30, Let's make this smaller. So let's see when we level up for the first time. So ten by 30, there you go, Because we are at level 2, are dexterity increases. Then our difference, then our dexterity than our defense, dexterity, defense, dexterity, defense, and so on and so forth. So as you can see, we are slowly increasing our players stats. Now, the other thing that we can increase is the max, HP and TMax Mano that our player can have. So I'm going to issue you a challenge. And your challenge is going to be to increase the HP and mono. So increase the max HP with every single level up. Multiply the max HP by zero-point. I'll just put an arbitrary number or any other ratio that you see fit and make sure to convert it to an integer. Do the same for the monks manner. So pause the video right now and go do the challenge. Okay, welcome back. So after we increase the dexterity and the defense, we are going to get the max HP. And it's going to be equal to Math dot floor to int. Because we are going to use the max HP that we had previously. And we'll multiply it by how much did I say is 1.06? Yep. That's it. 0.6 F. Yep, there we go. And as we know, every time we level up, we want to set the current HP to the max HP. So not all games do this, but some, or most games actually every time you level up your max HP as a small gift, the current HP that your ad goes to the max HP to your new Max HP. And we're going to do the same for the manners. So I'm going to duplicate this, has a couple of anthers and the max manna will have a different ratio. So maybe, let's make this maybe a bit small. You know what, let's make this point 18 and this 1.06. So we don't want a lot of extra mono. And the current Mano, current Mano becomes the max. There we go. Save that. Back in Unity. Wait for these crypto compile, run the code, and run the game. And let's see, when we hit L, There you go. The max HP is now 117, the current is 117 and the maxima increased, but also. So we go, there you go. You can see that we are slowly increasing the mana, but at some point we will move not only 1, We will move several point. There you go. Now we are going up by two and now we are still at two. Still up to some point? Yep. There we go. Okay. First still at two and at some point, I believe we will go three levels. Nope. Come on, come on, come on, come on, come on. Okay. I think that was three. Well, that done. I hope you enjoyed make sure to commit your changes. And I'll see you in the next video.
44. Game Manager: Oh, okay, so we want to keep track of several layers with their own stats because later on you'll see in our battle system that we have several players, several enemies attacking each other, so we can keep track of them on our main player, which is Jimmy the demon. We want to keep track of them on a separate game object or entity or script, which is going to be our game manager. So the first thing we're going to do is we're going to create a empty game object called The Game manager, and we're going to reset its position. This is not mandatory, but I like to it so we always know where it is. So it's not off somewhere in the distance. And we are going to go ahead and R scripts or right-click create a C-sharp script called Game Manager. At Enter. Wait for it to compile and you can see that it has a different icon on it. And this is unique to game managers. So Unity knows that this is a very important script that is going to be an almost every single game. So there you go, you can see it right here. Let's double-click. And what are we going to do in here? First of all, we'll want to make this a public static instance because we are going to be calling upon it a lot. So public static, game manager and instance. Great. And next we are going to create a serialized field that will keep track of all the players. So player stats, it's going to be of course an array, and we'll call it the player stats. Okay, great. Now and start, we're going to make sure that the instance is equal to this. We don't want to destroy onload. So we've already done this when we want to go to a different scene. We don't want to destroy this. And we are going to also make it a whereas our player, so we're going to make it a singleton pattern. So let's open up the player. And where's the players grip? There we go. Open up the script and let's copy this. Paste. Exactly the same. And the game manager, There you go. And that's it. That's all that we need to do for. Now. Going from here, there are two ways that you can go. First way is whenever we get to a certain map or later on a certain cave and restart facing enemies. You can go ahead and let's say, How can I say summon all the players available with a player stat to fight with you. So for example, let's say we have the healer here. We can add a players that to him or to her. And we can add another character, let's say the warrior. And we add a stat to him too. And let's say we encounter some kind of monster and our world as we were walking, then we need to fight him. So all the players that are in this scene will come to the aid of our Jimmy demon. This is the first mechanic to do this. So the way we do this is we're going to go ahead, will fill the player stats is going to be equal to find objects of type and its objects not find Object, find objects of type. Whereas it, so as you can see, it's objects of type. And this returns a, all the objects that we can find that are under the player stats. So we'll find all the objects of type player stats and add them to the player stats array. Now this is one way. The other way, as we actually go ahead and fill this serialized field manually. So for example, let's say we don't want to add the healer. So for example in here we'll add the first one will be the player, and the second one will be, for example, let's say, let's give player stats to the healer and BC. So you can see it has player stats. We can change them. Let's say we make dexterity to defense seven and maximum 200 and backstage be 30, and so on and so forth. So we'll change this to what's the Hillary's name? Sarah. So several of the healer. And let's say when we run the game, we can find all of the game objects. And we get Sarah and Jimmy, or we can do the other way and Indie Game Manager, we simply add the healer right here. And we can attach the player under the game manager and the healer under the game manager and take them with us through each C. So this will depend on how you want your game to work. I give you the full ability, but make sure to use at least one of them. I prefer just finding anybody that is in the vicinity and adding them. But this will require a bit of keeping track of how many players there are. You don't want to add, let's say 500 players to your game. So with that said, I will leave the choice to you. There is no challenge in this video, just that. And let's see, in Game Manager, I'm going to remove this one and this one. And now if we run our game, you'll see that we should find the healer and the player are both here because we have a player stat on each of them. So I hope you enjoyed, if you're enjoying the scores and you like me as an instructor to take the time to leave a review, it helps me out a lot. So that said, I'll see you in the next video.
45. Section 7: Menu UI: Welcome back, my fellow game developers. In this video, we are going to be creating a menu. So as you can see, we've created a menu. We've created several buttons and we put them all under the a single button object. I've tried to space them as much as I could. And now if we click on Maximize on Play, just so we can see it, much better. Ram, and there you go. You can see that we have items, stats, Save, Close and Quit button. We still don't have anything to show for it, but for now this will do. So. Let's not waste any more time and let's get started. Oh, okay, so time to create a menu. Until now we only had the dialogue panel will keep that out of the way. Now it's time to create a menu. And a menu will have many things in it. We'll have the inventory, a save button, a button and so on. So let's get started. The first thing we need to do is right-click in here and let's go to you i, and we're going to create a, Where is it a panel? So now we have a panel. We are going to go ahead and increase it to the fullest. And we are going to give it the background that we have. So we'll add the background and there you go. So this is going to be our menu. If you want, you can make just a little bit smaller, just a little bit so we can see maybe the edges of our gain. And there you go. So maybe a centimeter, there you go. So this will be the background of our game. And make sure that the resolution is 1920 by 1080, just like the scale of our canvas. The next thing we're going to do is we're going to add a button to this panel. And before we do that, let's change this to the menu. Now we have a menu and let's go ahead and add a button in here. So Find button. So we have a button and what we're going to do is we're going to get this button, will move it up here and we'll need to add some kind of background to it to make it look a bit better. And as a button background, we are going to use one of the resources that I've provided us. So drag this in here, and now we can drag it over the image of the button. And there you go, we have a very cool looking button. Now what to do about the text? Just delete the text, right-click on the bottom. And we're going to add our own text Mesh Pro. We are going to anchor it to our not, Let's not accurate. We are going to add the font to it. So the text tool add the font to it right here. We are going to make it completely dark. So there you go, it's completely black. We're going to call this items. So items. And let's go ahead and make the text fit in the correct place. And we're going to actually also change the button size. So let's just put them, this items. Make it so. And we are going to, let's get the button, make it a bit bigger. And because we are going to have how many buttons? 12345 buttons. So make sure that you save enough space for five buttons. I'm going to try as good as I can. So this is the first button, the items. There we go. And now it's time for a bit of a challenge for you. And your challenge is to finish the manual. So create the rest of the buttons. You can duplicate the button after you've configured everything. Mine is not perfect yet. I may change a couple of things and I'll give you a small hint. You'll need to have the stats, the Save, the clothes and the cuvette. So pause the video right now and go do the challenge. Oh, okay, welcome back. So a couple of things that I'm going to change in here, I'll either the underlying is already present. Let's see, let's see how it looks from afar. So if I increase the offset on the X, offset on the y, nope, that doesn't help keep this at 0 tons of Archytas. So I'm just experimenting seeing what works, seeing what doesn't. And if you've already done what you needed to do, you can skip over and finish. I'm just going to go ahead and maybe add a glow. What would happen if I add the globe through? Nope, I don't think adding a glue is good idea. Let me just make this a bit bigger. So I'm going to increase the size. Maybe make it bold. And the font size will be bigger. So there you go. Items looking good. And we are going to set this up correctly so that move the items. So there you go, items, I believe this will be good enough. Maybe shrink it down. There you go. I just want the skull to still be looking nice. So let's try this so good. That's changed the button name, tool, Items, button or item button or we can call it items. No worries about that. So let's duplicate this, Add next to it, duplicate this again, and duplicate this again. And how many buttons are there? Five. So duplicate this again, and there you go. This is the final button, and obviously they are not fitting. So I will not bore you with all of this. I'm going to stop the video right now. And the next one, we will continue on creating our menu. So I'll see you there.
46. Character Info: Welcome back my fellow game developers. And in this video we are upgrading our menu by creating character info. So if we run our game, you'll see that we have a very nice layout of the character and formation. We have the HP, mana and current XP was the experience that we need to the next level with the image of the player with his name under it and a very accurate number. So we are going to learn a lot in this video. It's a bit long. And creating UI is always a long process. You'll need to take even more time to make everything look better in your game. So let's not waste any more time and let's get started. Oh, okay, so what we want to do in this video is create a couple of panels and here maybe two, maybe three. I'm not sure we'll see and add all of the characters and fall in it. And not just any character. And for the character and fall of the player stats on the players that have player stats. So the first thing we're going to do, and I've already done it. I've created a game object which is called Buttons. I've added all the buttons under it, so make sure you do that. The next thing we're going to do is we're going to create a, another panel on the menu. And that's going to be representing the background for the character info. So we'll go into you. I will look for the panel. As always, we'll call this the character NFO. Nfo. And we'll change the background to use the element that we have. There you go. We are going to increase the Alpha. So it's completely non-transparent and we are going to make it very small. So in here, it's going to be your choice. If you want to have, let's say three, you'll need to make it a bit smaller so as you can see, but also make sure to make it a bit larger so we can fit everything in here. Delete, oops, that wasn't planned. So let's delete those, get the character and follow again. Let's see if three fit like this. Okay? Maybe need to make it a bit smaller. Okay, so let me again delete those. I'll just use this one. And we'll set it up here, make it just a little bit smaller. Okay, So what that done? The next thing we're going to do is we're going to go ahead and try to represent all of the information of the player in here. So what do we want to represent? We want to represent the HP, the mana, the current level, the experience that we need in order to go to the next level. And I think that's all that we need. If we do need anything else, will add it later on. So let's get started. Or we also need this pride of the character in here with the name. So let's start off with that. We're going to go ahead. Let's rename this to character NFO. So it's just character NFO. And we're going to add an image in here, so we'll right-click, go to you. I go to the image. There you go. And let's go and get the image of our character. So we'll just use one of those. Let's see the image, whereas the image, and we're going to drag it in here. We are going to click on preserve aspect ratio, and I'm going to set it to the native and then make it smaller. So as you can see, when we preserve the aspect or loop, let's set it to native. Now set preserve aspect, and now we should be able to make it a bit smaller. So as you can see, it preserves the size and we'll just adjusted, make it this big. I guess. So I'm not going to try and make this perfect. It's going to be your job. Maybe I'll do it later on because I don't want the video to drag on for too long. Now the next thing is we're going to add the name. So we'll right-click in here, go to you. I add a text Nash Pro. And let's go ahead and use the medieval color. The medieval font. So the medieval, we'll call this the car name. And let's just write in here player name. And let's add it under the player sprite right here. Let's make sure that it's small enough to fit and that it's completely black. Yep, there we go. And we'll make it bold. And zoom in. Let's see how that looks and that's under the player. Okay, great. Now, what else do we need to do? We need to add the HP. Let's duplicate this and move the character right here. So this is going to be the character HP, and this will be the character image. And let's see what we have in here. So the character HP we are going to make. So and what else do we have? Let's see, Let's make this smaller, make sure these aligned. Okay, so in here we're going to type HP two points. And I think this is not the best the font to use for this. If you want to change the font, I do recommend that if you find that this font is not good enough or doesn't look sharp enough from a distance. And what else do we have? Well, we need the mono, so we'll duplicate this. We'll have the mana and here, so the character mano. And we'll write in here mono. And let's just add something to make sure that everything fits, will add 100 over 100. So now we can see that it needs to be represented a bit bigger. And the HP also needs to change. So we're going to make it 100 by 100. And you can see that the current font doesn't have any special characters for the numbers. So if you want to add another one, I do recommend that if you want a cooler looking numbers, but I think those are good enough for now. So we also need to have the current XP, so we'll duplicate the character Manon also. There we go. We'll move it appear. And we're going to name this the character, current theme. And we'll write in here current XP. And let's just make this bigger. There we go. We'll increase the size, makes sure that they are all fitting in. We'll set it up here on the top right, the man in the middle. Okay, that's not moving. We need to move the entire object. And there we go. So now we have the HP, the mana, and the current will change this to a Nope, I meant on the current XP. Okay, there we go. And finally we want to see the experience that we need for the next level. So we're going to do something special about this. First, we'll duplicate this. We'll call it the XP to next level. Oh, go character. Xp to next level, and XP to next level. And instead of representing it in a normal number manner, we are going to represent that using a slider. So before we do that, let me just make this a bit smaller and reduce the spaces between the letters just to make it more findable. Just change it around this. And maybe they bit of distance between words. Okay, so that's good enough now it's time to add a slider. So we'll right-click on the character NFO, go to your eye. And you can see in here that we have the option to add a slider, collect on that. So now we have a slider right here to represent the XP. And now how are we going to change this? Let me just click on the character to next level, move down a bit, and take the slider, put it on the same level, and let's make it a bit bigger. So there you go. But this slider is very boring. We want to make it more exciting. So let's open up the slider and we're going to delete the handle slider in here. So let's delete that. The background image is going to change and the fill also. But let's go and add our own UI. So I've provided you with these. It's a very nice UI. They are the same as this one from the same folder. So we'll add the blue filler to represent or you can add the orange. I think I'll add the orange and the background. So let's go into the sprites, UI elements, and let's drag the slider background for the orange and the yellow. And let's just drag the blue and red will be using them later on. So now we have these. Let's go back into our slider, into the background. Let's add the background image to the background of the slider. And in the film, you can see that we also have a UI sprite. Let's add the orange fill to it. So now you can see if we click on the slider, you'll notice if we scroll down in the Inspector, we have the value. If we increase the value, there we go. We can see that we can move this orange line to get to the end. But we still have a couple of changes to do. So let's click on the background. If you look in direct transform, this is the way It's represented. It's stretched out on both sides. We don't want that. We want to hold down Alt and press the one on the bottom right corner, and you can see it will stretch out to all sides. Next we go to the fill area into the film and will stretch out all sides. There you go. So now we can get the slider. And if we increase the size, you can see that it fills the entire area. If we go to the slider value now goes from 0 to the full length. But there is a slight problem in here. You can see that it's a bit outside of the bounds. To fix this, we'll go into the fill area and just move it up here and adjusted to our preference makes sure that you adjust the two the way you want. Whereas the end and click on the fill area and here also, and there you go. So to stretch this out to fill everything. And you can also stretch out this to fill the entire sprite image. Okay, so let's make this a bit bigger. And there you go. Now we have our characters info, but there is just one more thing that we want to add and it's something that's available in all games where we have sliders that represent how much we still have to go. And that's an accurate number on this slider. So I'm going to issue you a challenge and that is to add text. So add a text to accurately represent the XP on the slider to avoid confusion. And you'll need to duplicate the character and fall for two other characters and our game. So pause the video right now as an XP text and duplicate the character on photo. Have two more. Oh, okay, welcome back. So we need a number. We have the slider. It's called this, the exposure slider. And let's go to the character and maybe duplicate, or maybe we should make this a bit bigger. I'm not sure we need to work on the small. And we'll say it's 100,000 thousand. And we're going to put it right here on the number as it goes. So it's not allowing me, maybe it needs more than 100. Just put in another extra 0 in here. And let's see how we can adjust this. There we go. So it's a very nice, clean number that allows us to know how much we really have loved besides the slider. So I'm going to increase the size on both sides. And finally, the last thing we need to do is we need to duplicate this character NFO and set it right here, duplicated again, set it right here. And if you want to have four, well, you'll have to make space or later on you'll learn a technique where we can change the layout of everything. Maybe add some kind of button that allows us to go to the next page. That is a possibility if you want to have more than three character. But as you can see, if we go back, if we click on maximize on play, run our game, and there you go. That looks really, really nice, especially when you see different characters. So we have the HP, the manna, the current XP, the experience to the next level. And this is a dynamic slider that you'll see how we can control later on. In the next video, we are going to be turning the menu on and off based on player input. Because currently as you can see, it's always in our face and we don't want that. So I'll see you in the next video.
47. Menu Manager: Welcome back, my fellow game developers. As you can see, we don't have the menu anymore. Well, where did it go? Let's go look for it with Jimmy. There's no menu, but if we press a certain key, yep, there we go. We have the menu, but if we pass the same key, it disappears, appears, disappears. And we can do this all day long. So let's not waste any more time and let's get started. Oh, case. So currently our menu looks good enough. Of course we'll be adding more things later on, but for now, we need a way to be able to close this menu and open. So we are going to do that and our menu manager obviously. So let's double-click on the menu manager and open up and Visual Studio, the first thing we need is obviously a reference to the menu. So we're going to duplicate this line. And we're going to create a game object variable. And it's going to be the manual simply menu. Next thing we need is we need a way to make sure we turn on and off the menu using some kind of key. And that needs to be the same key. So we don't need to use, for example, the M key to open the menu. And then the, for example, I don't know, peaky to close the menu, that's not very useful. We need one key to do that, and I'm going to issue you a challenge. And your challenge is going to be to check for input, turn the menu on and off using the M key or any key that you want. Because well, menu starts with, and so mg is the best one using in the update. So I think we've deleted the update. You can only use one key. As I've said. I'll give you a small hint on how you can use only one key if you already know or you don't know and want to challenge yourself, pause right now, go to the challenge. If not, check if the menu is active in hierarchy. So you'll need to create a condition. If it's active in the hierarchy, will turn it off. If it's not active, we'll turn it on and you already know how to set something active. That's another hint. So pause the video right now and go do the challenge. O K your welcome back. So an hour coding here under start, we're going to create the update. And you can see that it immediately iterates for us. We don't need to type private void, just type update and hit tab. So if the menu dot is active or active and hierarchy, then we are going to set the menu dot set active to false else. And I've just noticed that I didn't even type the use of the key. So I'll do it right now after I finish. And if it's not active in the hierarchy than the menu dot set active, there's going to be true. And we're going to wrap all of this in a condition that FV input get keydown. And on a key code which is the m, I will move all of these by holding down Alt and using the arrows heading tab. And there you go. So now and update, it keeps checking if we had the M key, we will check if the menu is active in the hierarchy. We will set it to false. If it's not, we will set it to true. Let's test this out. So I'm going to turn out the menu. I'm going to run the game. I'm going to hit the M key and nothing seems to be happening. Why is that? Because if we double-click in here, the menu and active hierarchy so you can see has not been assigned. So that means we forgot to do the most crucial step. And that in Canvas, we need to give it the menu Object. We will save that. We will stop maximizing on Play. We will run the game. And when we hit the M key, there we go. You can see that we have our menu. If we hit the M key again, there we go, it goes away, on and off it goes. So I hope you enjoy it. I hope you are committing your changes. I'm going to stage everything right now and I'm going to commit them. And if you are enjoying the course, you'll like me as an instructor. Please do leave a review. It helps me out a lot. So with that said, I'll see you in the next video.
48. Stop Player Movement (again): Welcome back, My favorite game developers. In this video, we are going to stop our player from moving when he opens the menu. So when we open the menu and we were still able to move our player. So now when we move in our world, if we open the menu, you'll see that we can no longer move. And I did something very weird and you owe. So I'm able to control the slider using the rake as the mouse, so we'll deal with that later on. But for now, let's not waste any more time and let's get started. Oh, okay, so currently we have a menu that we can turn on and off. So if we press the MK, you're going to see turned on and off. Very good. But the problem is, as we are moving, we can turn on the key and we can continue on moving. And that's not something that we really want. We want to stop the player from moving when he opens up the menu. Now some games do have the option, not the option. Well, whenever you open the menu in those games, you can still move like, for example, Dark Souls. But we are going to create something different. We want the player to stop. So we've already done something similar to this. If we go into the Whereas it the dialogue controller. Here, you can see in here that when we open or when we are talking, when we start the conversation, you can see that the player dot instance, the Activate is equal to false. And until then, no, we are setting it in a different place in here. So we are setting it to true when we activate the dialogue and then back to false when we stop talking. This is good. Now we need to add it in a different place, which is the menu manager. But there is a small problem. These might contradict themselves. If we are activating the player movement from a lot of places, we can encounter problems where, let's say we stop moving or let's say we open the dialogue and open them and you. So now we can start walking. We can even test this out and our game when we add it to the menu manager. So we want to avoid this. We want a centralized place where we stopped the player movement and what better place than using the game manager. So Here we'll create two variables, a public bool. And they are going to be the game menu opened and the dialog box opened. And now an update, we are going to check for these two. So if Vi game menu opened or the dialog box opened, then we are going to access the player dot instance dot the activate movement and set it to true. Else. If none of these two are open, then we are going to set the third instance of deactivate movement to false or if one of them closes a great. So now we have a central place where we can stop the movement, but we still haven't assigned them. And it's going to be part of your challenge. So your challenge is to set the Boolean in the correct place. So we need to stop the player from moving in two places and our scripts, so two scripts, we need to stop the player moving. We need to adjust one of them. And we need to set them using the instance of the class. And of course, the class that I'm referring to is the Game Manager. So pause the video right now and go do the challenge. Oh, okay, welcome back. So first thing in here, when we press the Encke will access the game manager. Instance, thought the game menu open and it's going to be equal to true, will duplicate this line. We are going to move it down and we'll set it to, or no, this one should be set to false and this one is true. Menu is opened as equal to false. That means this is no longer true and we need to activate the movement is set to false. Okay? We'll test this out in our game, makes sure that the logic works and what else? It's true, okay? And the next thing, we need to change it in the dialogue controller. So instead of the player dot instance set to false, we're going to go into the game manager. Dot instance dot. The dialog box opens is equal to false because in here we finished talking. So the current sentences are greater than the dialogue sentences available or the length of them. So the dialog box is closed. And in here, when the dialog box opens, it's going to be the game manager dot instance, the dialog box open set to true. So let's go ahead and test this out. So let me just show you one more time. So maybe you didn't catch that. I moved on very quickly. There you go. Now let's go into our game. Let's hit play and we can walk around when we hit the M key. Yep, there you go. We cannot walk around. You can see it from the grass, from behind. Or we can double-click on the player. And there you go. This is our player. We tried to move around. Yep. And this is one of the features of having a, such a huge canvas. We can look at the Canvas on our game menu, yet still see in the scene properly what is happening. Okay, so now we turn off the canvas or the menu. We can go back to walking around perfectly. Now let's go ahead and talk to our little healer in here. So we had the key. Can we walk? Nope, we can't when we finish talking, Yep, we can walk again. So I hope you enjoy it. I hope you are saving your repositories and I'll see you in the next video.
49. Setting Up Stat: Welcome back, my fellow game developers. In this video, we are going to be setting up all the stats. So when we run our game first, when we had the M key, you'll notice that we only have two character panels if we remove now the healer, we run our game. You'll notice that when we hit the M key, we only have one because we only have a single player or character and our world that has a player stat on him. So let's not waste any more time. And we need to move the update stats and to the else. This is something that I will make a huge mistake. So let's not waste any more time and let's get started. Oh, okay. So currently, let me turn on the menu. Currently we have everything set up. So we have the HP, the amount of the current XP and so on. Everything set up in terms of UI elements. Now what we need is we need to convert these UI elements and to real character and forth using the player stats that we have on each of our players. So we are going to do this in the menu manager. If we go into the canvas, double-click on Menu Manager. And we have this group right here. First off, we need a reference to the player stats. So create a serialized field in here, which is going to be a, oh, you know what? We don't even need to make it a serialized field. We can make it a private field. And we can move it down here now and just remove this. So now we'll create a private player stats array, which is going to be called the player stats simply. The next thing, because we are accessing UI elements, will need to make sure that we have using Unity engine UI. And now we want references to the different elements that we have. So we need to put them inside of a bracket, so a serialized field. First of all, it's going to be a text and way and it's going to hold the name text is going to hold the HP text. And it's h p text. It's going to have the mana text, the level text, the XP text. And I think that's all we will add to this if we find that we need to and maybe I should move this up or down. No, I'll just keep it will keep all the elements that are together without any spaces between them. So next thing we need is a serialized field for these sliders. So a slider, it's going to be, of course an array because we have multiple sliders. So XB, slider is the name of our variable, will need a serialized field array for the images. So serialized field in each array and the character, oops, the character image. And what else do we need? Oh, we need to keep track of the number of panels. So currently we have three static panels, but let's say we only have one player with player stats in the game, or we have two players. So we don't want to have a third one. This will just make everything fondly. So what we'll do is we'll also reference this. So we'll create an array of game objects. And it's going to be the character panels. So character panel, save that. Now we're going to set everything in Unity. So if we go to the menu managerial, see that we have everything in here. We are going to lock this and then we'll go to the character and false will open all of them. So we'll open all three. And we're doing this because we want to drag and drop all of them. So instead of adding every single one, we go like this. And instead we are going, for example, character name, character name, character name. And we'll drag them all in here. And it's not allowing us because please can I drag it over here? Nope, I can't y, y, y, o. So this is not a tax. This is the MP Pro. Save that. Now, let's try this again. We choose these three and we can't use the MPI Pro because we haven't added the using TM probes. So now can we continue? Again? It's telling me there's an error. Namespace JMP Pro. I've added, we are using the TMP Pro. What's the problem? Let's see in the dialogue controller, yup, there we go to JMP Pro, the MPI pro. I think it will resolve itself in just a bit. Text Mesh PRO techs mesh GUI, save that. Okay, so now finally, we are going to choose the character name, character named, character name, and drag it over to the name text. So as you can see, there we go. The first one is referenced to the first one, the second one and the third one. And this will make everything easier. Next thing we have the HB. So HB character, HB, character HP character HB, drag it into the HB text. So there you go. Bhp, BHP. Next thing is the mano a mano, a mano, man. Direct and text. There you go. So make sure that the first one references the first one. We have the level text. So current XB, Jacqueline here, the character to next level slider. So this is ordinal, the XP slider. Drag it into the XP slider. The character image, which is something that we'll need to change. So the character images or not change. What we need to do is we need to actually add them envied player stats because we haven't done this already. The character infos and to the character panel. And finally we have the XP text, XP to the next level. I think this is it. So character SP2, next level, I believe it's this. If we go back to our scene, yep, There we go. So everything now is set up. One thing we need to do is we need to go into the player stats. We need to go up in the NFO and inherit. We're going to create a serialized field, which is going to be an image. And we're not using UI elements. So it's going to be an image and it's going to be the character image. Save that back in Unity. Where do we have characters? So let's close the canvas for a second. Go in here. And now we can stop the locks or press on the log so we can again see what's going on in here. We need the image, whereas the image, we can drag the sprite renderer. Will that work? Nope, we'll need to open up, find the image, and drag this image in here. And it's not taking it because it needs to be a sprite. So as you can see, I also make a lot of mistakes. Needs to be as bright and we'll drag the healers Brighton here. So there you go. Save that back end. Or our player also. So Jimmy, whereas gimme, gimme your sprite. Very go, save that. Now, I think this will work. Maybe it won't just because we need to change the where is it in the menu manager. This should be maybe a sprite. We'll see what happens in just a bit. Now, next thing we need is we need a method to update the status. So we're going to create it. So before we fade the image, and here we are going to create a public void, update stats. And what shall we be doing in here? Well, the first thing is we need the player stats. So we'll write player stats is equal to the game manager dot instance the player stats can we access it? Nope, because it's a serialized field, whereas the game manager, it's a serialized field. Let's do it the more professional way. So we're going to create a public or public player stats array, and we'll call it the get player stats. And we'll simply going to return the player stats. So there we go and we need to make it an array because its return type is an array of players stats, not just one player stat. Let's test this out in here. The player, the player stats. So there you go. Now you could have avoided this step of creating a method. You could have just changed this to a public and then used it. But that's not the most professional way of doing it. We don't want to have access to the player stats because we don't want to be able to modify them. We only want to be able to get them. It's no problem when you're creating the game, but For some reasons somewhere you try or maybe you just manipulated the player stats a bit. You'll have a lot of problems. So using methods like these, really avoid those types of problems. We don't want to manipulate the player stats. We just want to get them. Okay, so with that out of the way, what else should we be doing? If we go into our menu manager will need to update the status every time we open up the menu. So after opening up the menu or before actually, let's update the stats. So update stats. Okay, so finally what we want to do is we want to go ahead and turn off any character panel that is not used. And to do that, I'm going to issue you a challenge. So your challenge is to activate the character panels. So create a loop that goes through the player stats and turn the Character panel on for the available players. So first thing first is you need to turn off the character panels in Unity and then use the loop to turn them back on. So pause the video right now and go do the challenge. Okay, welcome back. So we're going to turn all of these off. We're going to save that back in here. We're going to create a loop. So for int I equals 0, for I less than VT player stats dot length. And for increasing by 1 every single time. Let's first of all just print out how many i's we have. How many AI is not our actual eyes, the eyes and here, okay, That was a bad joke. We are going to access the character panel at the position I. And we'll set active. True. Save that. Now back in here, let's see if that works. Let me turn off the menu. Hit play. So now we hit the M key and we have nothing. Why is that? None of them have been turned on. So oh, there we go. So you can see that two of them have been turned on and it took a while. Why is that? Save? Do we make sure that everything is working correctly? Let's turn up the MPC for now and see what happens when we run the game. We had the M key. There you go. So we have only one of them active because we've removed the healer. We need to turn the healer back on. We need to run the game so the game manager can actually find. So we have an M. There you go. We have to, you can see that we have a slight problem of fixing these, pressing the two times, but everything seems to work fine. But we still haven't finished because we need to fill all the information that we've set up. We'll do that in the next video.
50. Updating Stats: Welcome back, my fellow game developers. In this video, our menu will actually do something useful. So if we look on our healer, let's say the current XP should be 50, the current house should be 60. And nope, because the maximum is 30, that's set it to 20. And the current mana will be three. We will run our game. We will hit the M key and you'll notice that we have everything set up in here correctly. We even have these sliders. You can see that it's exactly in the middle because it has, or she has, the healer has Sara 50 points out of a 100, so it's exactly in the middle. So let's not waste any more time and let's get started. Currently, we are only setting the panels to active. The next step is to actually go ahead and use the where is it on the player stats. So for example, setting the players level, the current XP and so on and so forth. Now some of these will need to be public in order to be able to access them. So let's get started. The first thing we want is the name of the player. So the name text at the position I. And we are doing all of this inside of the for loop. So we go through all the players stats that are available. We need to make sure that it's dot txt and it's going to be equal to the player stats at position I, that the player name. So as you can see, we need to change a lot of these. Now. We've done it in the more sophisticated manner before. But I don't think it's worth the hassle of creating a method for each of those. So we can simply go ahead and make it a public, will make the things that we need public. So it's going to be the dot player name. There you go, Save that. Next thing we are going to get the HP text at the position I, the tax, the player. Now in here we are going to do something different. Because if we go back, we run the menu. We turn off, turn on one of the characters. You notice that HP isn't simply the number. It's also the concatenation with the word HB. So if I double-click on the canvas, if I click in here, you'll notice that character NFO is HP dot and the number. So what we need to do is we need to take that into account. So we're going to write, first of all, open up these two quotes. Quotes, okay, So HP, and then we'll add the two points, and then we add a plus. And we did this previously in one of our prints. This means we are concatenating a integer with the HB. So then we are going to add another plus. We're going to add the forward slash and another plus, and it's the player stats. I thought Max HP, and we need to go and here. Whereas the max HP, the max HP is public and the current HP is also public. Save that back in here. Current HB, Max HP, save that. Okay. Next we have the mono. So we need again to go back in here and make them public. And click save that back in here. And the text as the current manner and the maximum. So how boring is this to do? But it's necessary so the level text dot txt. Oh, and also we need to change the strings in here. So mana, AHP. Now the level. So what do we write in here? The, oh, we didn't even create a level, so it's the current this level tax should be changed, I think so. Go in the Canvas, menu manager, the level text, it's the, okay, so it's the current, so we need to change. I don't think leveled texts really represents the correct word, so I'm going to change this to the current XP text and apply it. So the current XP is the player stead the current XP, and we don't have that. You can also add a tax to the level. So the level that our player is at, make this public, save that back in here. Current XP. And we don't think any of those. Save that. And what else do we have? Well, we have many more, but for now, let's save That's going here. Let's turn of the character and fall term of the menu. And before I forget to eat, we used to have the update stats in here, but I put it in here thinking that that's where we open. Actually know that n here is where we actually open the menus. All this is where we are going to call the update stats back end our game, run the code and now we see that when we hit the M key, we have an outside bond. What's the problem? So we are looking at the current XP text. What's the matter? Okay, welcome back. So the problem is we changed the name of the variable without setting it in here. So back in the menu manager lockdown, that's open up the character NFO. Let's get the character whereas character current XP. And let's drag them in here. So there you go. Save that. Now we shouldn't have any problems. We run the game, had the MP. Yep, there we go. So we have the HPs over 100 minus 0 over 30, and the current experience is 36. So if we want to go check it out on the player, Let's unlock this. We can see that the current experience Thirty-six, great. The next HP is 100, the current h be 0. If we make it 20, and we turn off the menu, we turn it back on. There we go. So we have 20 HP. So this looks or seems to be working. And now we need to finish up the rest and is going to be your challenge. Your challenge is to complete the experience tax. So update the slider. And first of all, before you update the slider, you need to update the maximum value on the slider. What do I mean by max value? If we look back in here, if we click on the slider, you can see that we have a value and here we have the minimum and the maximum. So if we say make the maximum value 50, you'll notice that we go from one to 50. You need to make sure that you update the value on the sliders. So with that said, let me take you back to the challenge. Pause the video right now and go do the challenge. Oh, okay, welcome back. So first thing we need to do is we'll need to go into the XP slider. Okay, So XP slider on the position i dot max value, it's going to be equal to the player starts at the position I dot XP to next level, and we don't have it. So the x B2 next level is public. Save that, and let's see. So for the next level. And in here we need to do something very important. We need to get the expert to the next level at a certain position. So what we're going to do is we're going to get this position by looking at the player stats at position I, that player level. So we need the level and the level of the player needs to be public. So I know many of you might have stumbled here. This was the hard part of the challenge. I hope you got it right. So why are we doing this? You might be asking, so what happens in here? If we go to the XP for next level, you'll notice that it's an array and we want to get the certain position. So we need the level of the player. And using the level of the player, we want to access the experience to get to the next one to set it. So that's why in here in the menu manager, we are using the player level at position I and getting the level that his ad and using this whole integer and ordered to look through the XP for the next level. So I hope that wasn't too hard as a challenge. And now we are going to access the value, the players that dot I. And we are going to use the current exp, save that. And finally, we need the XP taxed. So the XP taxed at position i dot text, of course, is equal to the player stats at position I, the current XB dot two string. So this was one of the second challenges. I know this challenge was very hard. What we are doing in here, if we don't add a dot to string, you'll notice that we'll get an arrow. So this arrow tells us that we cannot implicitly convert an integer to a string. So to convert it to a string, we are going to write toString. And then we'll add the concatenation with the forward slash. And then we'll access the player stats at position i, dot XP to next level at the position that we've already created in here. So what's the next level? Set it in here. And there you go. This should cover almost everything if we didn't make any mistakes. So now if we, let's add the NPC healer again. So now when we run our game, we had the M key. There we go. We have the experience to the next level because we have, maybe we should have written these in white. Let me maximize on play so we can see them more clearly. So when we had the MK, There you go. So to get to the first level, we need 100. We'll make this a different color. We have 36. So you can see that the slider automatically changes and we don't have the image for Sarah. Why is that? Because we should have made this not an image, but a sprite. And I'm sure that's the problem. And not even that we haven't assigned it even. So in here we are going to get the character image at position I will. So character image at position I dot the sprite. So why are we doing this? Because if we look back on one of our, let's say character image in here, you'll notice that we have the image and the need to replace the sprite on it. So the character image dot sprite is equal to the and we need to make sure that the, where is it? The sprite on the player's stat is public. So it's going to the players that at position i dot character MHC2. We'll save that. We'll go back into Unity and hopefully the image will work. So when we had the M key, very goal. So even though Sarah doesn't look as good as she should, everything looks to be working fine. Everything is working correctly. So I hope you enjoyed this very long video. We are around 20 minutes. Some editing will help hopefully, but we have everything done. And the next video, we'll be creating a way for us to navigate through the menu. So I'll see you in the next one.
51. Using The Buttons: Welcome back, my fellow game developers. In this video, we are going to put our buttons to use. So if you remember, our buttons didn't do anything. But now when we hit the items button, we get a different panel. When we hit the stats, we get another different panel. And when we quit the game, you see that with, with the game. Unfortunately because we are still in the Unity editor, the quick doesn't do anything. It will later on when we build our game, but for now, it works by printing out something to the console. So let's not waste any more time and let's get started. Oh, okay, so currently, if we run our game, you can see that if our game runs any day now, if we hit the M key, we have the menu. Everything is set up pretty much correctly. Maybe we need to fix the sprite on the little hilar right here, but the buttons aren't working. Why is that? Well, because we haven't given them anything to work with. So we need a way to, whenever we click the status button or the items button, we want to open up in other many. So we're going to open the Canvas, open up the menu so we can see everything. And we are going to go ahead and put all of the character and for under a single empty objects, or this will be the character NFO. And we're going to drag all three and to the character and for IT. And next thing we're going to do is we're going to create a new panel. So go to your eye panel and we're going to make it a little bit smaller so it fits in right under the buttons. And we're going to give it the background that we're using. So go to the elements, give it the background we are always using and turn, whoops, where's it? So we turn everything on completely. There we go. We can even make it bigger. So let's make it just, oops, no, we want to make it a little bit bigger. So there you go. So we have more space to work with. And this panel is going to be the items panel. So the items or items or items panel at depends on you. What you want to name. It just needs to represent what the items are correctly. Okay, great. So now we need a way to turn this panel on and off when we collect the buttons. Now there are many ways we can create a method in the menu manager to handle this. Or we can go to the Items button. So if we open up the buttons, we go to the Item button. If we scroll down, you can see on the bottom game component or the button component, we have a onclick. This onclick, it does what it says. Whenever you click it, it does something and we can add in here a function for it to do. So you can see currently we can add an object and this is where we will be. Oops, sorry. So if we go back to the Items button down here, we can drag the items panel in here if it lets us. So the items panel, and you can see that currently there is no function. If we click on it, we have many options, and one of them is the game object. So we can access the game object and do many things with it. So for example, the string name and so on. But what we're interested in is the set active book. So if you click on here, you see that we get this small checkbox. And this small checkbox represents if we want to set active to true or if we want to set the active to false. So if we set the active to true, that means this panel will be set to well active. So now if I just turn off the items panel, if we run the game and let's turn off the menu, turn it back on. So if I click on the Items, very go. How cool is that? If I click again, nothing happens because it doesn't have anything else to do, it just turns on the items panel. So this is how we are going to open up and close different menus. So with that knowledge, it's time for you to create thes states panel and duty challenge. Your challenge is to complete the stat button. So you'll need to turn on the stats and everything else off. And I'm not talking just about the character NFO. I'm talking about the stats many. What do I mean by that? As you can see, we have a stat button which is different than the regular character information that we've created. So with that knowledge, let me go back in here. Pause the video right now, create the stats panel. It doesn't need to have anything in it, just like the items. You can duplicate the items panel and you'll need to set the status button. So pause the video right now and go do the challenge. Okay, Welcome back. So let's go to the items panel. We are going to duplicate it and we'll change it to the status panel. We'll see what the status panel does later on. So we'll go into the stats. We are going to turn on the status panel. We'll drag it in here, set the game object to set active, and we'll set it to true. But not only that, the challenge also says and everything else off. So we'll go back in here. We are going to create another onclick object under the stats panel. We are going to drag the items panel. And here we are going to go to the game object, set active, and we'll set it to false. So now when we click the status button or the stat button, we are going to set active. The stats should be the stats, not the status. So the stats. So when we turn on the stats panel, we turn off the items panel and we'll do the same thing right here for the items. So how are we going to know the difference? We're not right now. Later on, see that there is a difference. If you want, you can add maybe a little something that differentiates the items from the stats. Let's go ahead and do this. Actually, that's a good idea I just started with. Let's just make it a bit smaller. So now we save that. We are going to turn off the stats panel. We are going to run our game. Let me just exit, turn this back on. Go to the items. There you go. This is the items panel, the big one. Now we should have a smaller one when we had the stats. There you go. We have a smaller one. We still have the characters right here. You can also turn them off. So character NFO should only come up when we enter. So we'll see how we can figure that later on. We also have the last thing which is the Quit button. And for that, because we want to quit and go out from our game, we are going to create a method for that. So we'll go into the menu manager. We will create a method in here and it's going to be a public void, quit game. And in here we are going to write application dot. So what this does, it will take us out of the application. But because we haven't built our game yet, we are still using it in the Unity editor. It won't do anything. So what we'll do is we'll use debug dot log. And we'll just print out a message in here that says, We've quit the game. Save that, go back into Unity. And let's see how we can do this. We are going to go into the Quit button, scroll down at onclick object. We are going to, where is it? Where is it we are going to drag and the canvas because we are using a method which is on the menu manager. So whereas the menu manager, it's on the canvas, there you go. The menu manager is on the canvas. So we drag and via Canvas on to the object that's being asked for in here, the non-function will click on it and you'll notice that we should have a menu manager. And in here we can access all the methods that are there. And one of them is the quit game. Fade image is also one of them. So whenever you want to call a certain method from the onClick, make sure that it's public. So we are going to save that. We are going to turn off the menu. Let me turn off the menu. We'll run our game. We've had the M key, will click a quit. And there you go. You can see the message printed out to the console with quit the game. So with that done, I hope you enjoy it. In the next video, we are going to be creating our stats panel, adding everything we need to end there. So I'll see you in the next one.
52. Setting up Status Widow UI: Welcome back my fellow game developers to this very, very long video. It's long because we have a lot of you I to setup. So now if we had the M key, we click on the stats. There you go. You can see that we've created a Stats menu. We have the name the dexterity defense equipped weapon, armor, armor defense, and so on. They also have these names in here, and they are not just for show. If we turn of the MPC healer, there we go, We turn it off. We go out, we go back and we hit stats. Okay, that's not working. That may turn off the healer right here. This is so awkward. Had the wrong game. Please work. Okay, so there you go. We only have one name because we only have a single character that has a player stats on them. So let's not waste any more time, and let's get started by setting up these stats many 0. So in this video we'll be laying out our stats. So we're going to turn on the stats panel and we're going to try to reset it to its previous size. And let's click on the Tiki, which will allow us to go to the rec tool appear and we'll just make it that big. So there we go. This is our stats panel that we are going to be filling in. So the first thing we're going to do or let me tell you the vision of what we're going to do and you can adjust your own vision of how you want to, the stats to look. We are going to add maybe three buttons in here or four buttons depending on how many characters or players you want to have. And then we'll add an image in here or in here or anywhere, maybe I think, to the left to represent the player. And then we are going to add all these stats in here. And you might be wondering why is this different than the character info. Character NFO is just for like how much does display or have health. But this will represent how much the player has defense, dexterity and what weapons he will be equipped thing later on when we actually create weapons to equipped. So this is the job of the stat span and not the character. Character is just a quick look. This will be an in-depth look of what the player actually does. So let's get started. First off, let's right-click in here and we're going to create our buttons. So we'll go into your eye and we're going to create a button. Okay? I thought for a moment there I didn't click it. We're going to give it the background image that we're used to. And we are going to set it up here so we'll make it a little bit bigger. There you go. I think this is enough. And we're going to remove this text. We're going to add our own text, Nash Pro, and we're going to give it the medieval. Where did it go? So we're going to give it the medieval irregular. Sure, well, it's called, it's going to be called the player name. So there you go, the player name. It's also going to be the name of the text. We don't have to do this, but we'll just change it. Will make it bold, will make it black. And just like always. So nothing different right now. And let's see what's happening in here. Let's adjust the text to the proper size. And there you go. Maybe we'll make the font just a little bit smaller. Okay, so there you go. This is the player name. I think this button is enough. We'll call it the Layers button. And we're going to go ahead and duplicate this two times. So duplicate the swans, drag it down a little bit. Duplicate this another time, dropped down a bit. So there you go. Now we have these three players, and I just hope the distance is correct knowers. So there you go. Next we're going to add an image. So we'll right-click in here. And before we continue on, let's just make this under a single game object. We have a very nice hierarchy. So as you can see immediately, this gets a lot confusing. So I always recommend that you create buttons, staffs, Panel, Buttons in the stats panel and so on. So you have very good organization. Okay, so next thing is the UI, the image, and this will be the player's image, player image. And let's just give it the default image of our player. So where are they in the characters? Give it this one. So there you go. We are going to set to native SIFS preserve aspect will make it a bit smaller. And I'm not sure where you want to set this may be in here and then set everything on the right. It will depend really, it does depend on your take your time. I'm doing the everything that's related to your eye. I'm trying to go through it because it's not, not much like you're not learning anything by duplicating buttons. So I like to skim over them a bit faster. So take the time to create your own layout. So the player image, we are going to right-click and we are going to create two sets of, let's say things. We're going to have the labels on the left and the values on the right. And we got to have actually, you know what, just go to the buttons, go to any of these buttons, duplicate the player name, and we'll set it outside. So there you go. Now we can use this one. It's much faster. And this first of all, it's going to be the name, so the player name, and we'll just make it a bit smaller. There you go. So name. We're going to duplicate this again. This is going to be the HP will duplicate this again, and we'll set all of these before we start duplicating this, let's create a empty game object, the labels, and we'll set all of these under the labels. And we are going to make them face on the right like this. And let's set them on the middle so they are all adjusted to the right. We are going to name this the, the HB. Again, we're going to do.
53. Displaying Status Widow Information : Welcome back, my fellow game developers. In this video, you will notice that I have made a lot of mistakes, but we did get something none. So if we go to the stats, you can see that the name is Jimmy HBS, 0 to one over 100, dexterity 1030. But what happens when we click on Sarah? There you go. You can see that all the stats change and we can go back and forth through them. So let's not waste me more time and let's get started. Oh, come back. So what we are going to do now is we're going to set up our status panel. So we're going to set everything up including the buttons. The first thing we need to do is we actually to set the correct names on the buttons. And there's going to be your challenge. So your challenge is to set the names, so sad the names of the players on the buttons. Inside the loop access the tax component on the buttons, and use the Get component in children to access those texts. So you only do a bit of research on how the Get Component and children works. This will save us a lot of, let's say, serialized fields that we will need to otherwise add. So ResearchKit components and children and use it to add the component on the gay. So I'll see you in just a bit. Oh, okay, welcome back. I hope you tried to do this. So how does this work? We are going to go ahead and use the stats buttons on the position I. After we've set it to active, we are going to get the component and children and I'm not going to open the dogs. I hope you tried to. But as you can see, it returns the component of type, type, the game object of the children. So we're accessing the buttons right here, and they have children which are the player name or these texts. So we are going to access them. So we're going to get children or components in children. And as you can see, it's going to ask us what type do we want to access. It's going to be of type TM per row, no text Mesh, mesh pro GUI. And we're going to access the text element on them. And it's going to be equal to the player stats at position i dot layer name. So we are going to save that. We are going to go back into Unity and wait for this to compile. Turn off these tabs panel. Let's run the game and let's see, had the MPI open the stats and there you go, Jimmy. So we'll need to adjust the name just a bit on these panels. If we look in here, where's the button? So let's open this up. We're going to set them to be in the middle. And I think that's enough. Save that. Let's turn on the healer. Try this one more time. Make sure that it works. And we're going to turn this AP Stats. There we go. So Jimmy and Sarah. So I hope you understood how get component and children works. So the next thing we're going to do is we'll need all the variables to represent the labels and the values. So let's open up our menu manager and we're going to need a lot of serialized fields. So first off, let's go ahead and create a serialized field for the text or text message pros or text. I keep forgetting we are using text Mesh probe text Mesh, pero, You Gui. So it's the stat name, the stat, HP, stat mano. And you know what? I'm going to issue you a challenge and we're going to see who can complete all of the things we require first. So stat mana, that decks, stat defense. And then we'll need one more. And it's going to be a image. And the character stat. Much. There we go. The next thing we're going to do is we'll create a method to actually update the stats. So in here under the Stat menu, we are going to go into public void and create a Stats menu update. And because we have different, That's what they call them, the character information, we are going to give it an argument. And this argument is going to be an integer and it's going to represent the player selected number. This method will be called every time we click the buttons of the players. So you saw we had Jimmy and Sarah. And whenever we click Jimmy or Sarah, we will pass on a variable in here. And based on that variable, it will update all of the states and all of the values and labels. So first of all, we have the name, so the stat name is going or dot txt actually is going to be equal to the player's stat at the position, player selected number.net or dot player name. And because we are going to be using this every single time, we'll create a variable which is going to be called the pipe player stat. It's going to be called the player selected and it's going to be equal to player stats at position layer selected number. And now we can immediately use him in here and save a bit of code, so player selected. Okay, great. Now next thing we're going to use the stat HB. It's player selected, the HP current HB, and we are going to concatenate it with a max HP. So plus player selected Max HP. And I think we need to make sure that this is a two string to avoid any errors. Next we have the mono. So Stats manna, manna will not create the Mano. No. Yes, we did start Mano. So why is it not showing up? That manner? There you go. So current Madonna and the max manner. Okay, great. Next thing we have the dexterity. So let's create, will put it on a separate line. So what did we call it the stat decks? I believes that decks, there we go. We're going to remove this and we're going to set this one to dexterity. So do we have access to the dexterity on the player stats? I don't think so. There we go. So dexterity should be public and the difference will also be used. So let's make it public. Save that back in here. Dexterity, dot ToString, duplicate this stat defense, defense toString. And finally we need the character image. So the, I don't know why I duplicated this. We don't need it. So the character image sprite. So it's not allowing me to access it because also this should be the character static image. So character and stat image, dot sprite. There we go. And it's going to be equal to the player selected dot player sprite. What do we have? What is called in here? Let's check character image. Okay, so character image. There we go. And let's save that. And in Stats menu, we are going to call this only once. So that's called the Stats menu update. So Stats menu update. And let's just go with the 0, which should be the Jimmy, I think. So we'll save all of that. Let's make sure that we've saved. Ok, so everything should be in place. We'll go back into Unity. We are going to save this. We are going to run our game. And now if we click on status, there you go. We have not reference anything. So we haven't referenced the the stats name. We haven't referenced anything. So how many times should Michael do this mistake until he finally gets it? I think it will take a bit more time. So the player name, PHP, V1, dexterity, defense and the character image. Whereas the character image, okay, So it's, I think there it is. So the character image and everything else like the equipped weapon and so on, will not be using for now. So now we run our game stats. There you go. And nothing seems to be working BY cause O. Instead of giving it the values, I've given it the labels. Very smart move. Again, let's turn the lock. So as you can see, Michael makes so many mistakes before he finally gets it. And I'm going to keep this end the video because it's important to know that nobody's perfect. Let's go back. Let's run the code so please This time we hit the stats, we have the name Jimmy HP, 0 over 100 minus 0. That's because we didn't change it on the player, and so on and so forth. Dexterity, Stan, defense a 30. Everything is working. Now. We need to change it in the onClick. So now these, if we go to the buttons which are here, you will see that we have three buttons. The first button on the onclick does nothing. We're going to add a function to it in the Canvas. We're going to go to the Menu Manager, we are going to Stats menu update. So as you can see, because we added a parameter, it asks us for a integer. The first one is going to be 0. The second one is also going to have the Canvas menu manager one. And the third one will have also the Canvas menu manager status update with integer of two sub 1 or 0, 1. To save that. Let's hope this works and I haven't made another mistakes or stats. Jimmy, Sarah, There we go. How cool is that? So as you can see, we have the image changing. Obviously, we need to make Sarah little bit smaller using these gutters, but everything is working so you can see the dexterity, the strength, demand, and HP, even the name changed based on which button we click. So how hard is that? I hope you enjoy it if you're enjoying the course so far, even though I've made a lot of mistakes, I hope you will like me as an instructor. And if you do, do take the time to leave me a review, it helps me out a lot. So I'll see you in the next video.
54. Section 8: Creating Items: Welcome back, My favorite game developers. In this video, we are going to be creating an item manager that is added to every single item in our game. And as you can see, we've already created a mana, health Ocean, two sets of armor and two sets of axes. And you'll notice that one of them is gold. One of them is just silver. So let's not waste any more time and let's get started. 0 case. So we need to create some items. First of all, so what we need is we need a script to handle these items or to determine what types of items these are, what name they have, what value and coin they have, and so on and so forth. So let's go ahead and start creating. So we'll go into the script, will create a folder in here that we'll call the items management. I guess manage meant. And we're going to open up, and here we're going to create a C-sharp script and we'll call this the items manager. Hit Enter. Wait for the script to compile. And let's go ahead and open up the script. So what do we need in here? First of all, this item manager will be available to many kinds of items. So first of all, we have the regular items like, let's say coins, potions and so on. We have weapons and we have armor. So how are we going to determine which is which? We are going to create something called an enumerator, different than the enumerator we use for the coal teens. It's a numerator of types. Let me show you what that is. We create a public in and the item type. So we've just created a new type of variable. And this can be applied to, or this can have three, let's say pipes. If you want a type with three pipes that it can have. And so maybe type is not the best word. But we can have either an item or we can have a weapon, or we can have an armor. So now each item needed to choose what type it is. We then going to create a public variable which is going to be of type, item type. So as you can see, because we've created an enum now we create, we can create a variable of type, item type, and it's going to be called item type. So now each item, for each item we can set which item type it is. Next thing we're going to do is we're going to create a string item name. And you'll notice that all of these are public because we want to speed up the process of actually getting this information. We're going to create another string. It's going to be the item's description. So far we know what we can actually create that on the same line. So the item name, the item description, and it's not necessary, but it's just better. And let's continue. And here we're going to create a public integer and this is going to be the value and coin. So the value and coins. What else do we have? We need to set the sprite. So it's a public sprite. And it's going to be the item image. What else do we have? We need the amount of effect that it does. So if we have, let's say, for example, a portion, if we have an item, we want to tell it, what's the amount of effect? Will it give us 100 HP, 200, or 700 HP? So it's a public integer amount of effect. And we're also going to create an enum for the type of effect. So we're going to have a public enum and it's going to be the effect type. And we're going to have two types. It's going to affect either the HP or the man. What else do we have? We need, we'll need to create the public affect pipe. And it's going to be called effect type just for the simplicity of things. And finally, we need something for the dexterity and defense of the weapons and armor. So public and weapon decks 3080 and the public and armor defense. So armor defense. Okay, So now I think every single aspect of an item set up. Now we'll need to go ahead and create some. Now if we go back in here. We are going to go into the resources that I've provided you. And this is a list of items that we'll use. So you can see we have different shields, different axis, the front, swords, and so on. We have hearts, we have blue portions, we have red portions for the, where did we go? So Lu potions, green potions and so on, coins, gems, all of these can be used in our game. So I'm going to go into the sprites in here, right-click and create a folder. Or you know what? I don't need to create a folder. We can simply drag this folder and here, but make sure that we have a separate folder for the item sprites. We'll call this the items sprites. And there we go. So double-click in here, you see that we have all of the sprites. Let's go ahead and add a couple of items. So we're going to add, let's say a armor. Obviously we cannot see this armor because it's behind the window. So again, please, armor, Where is it? Where is it? There it is for some reason it wasn't appearing. We're going to set it on the background. We'll set it to one. And if it's not very visible, we can increase the scale to two by two, let's say. So there you go. We have the item on the ground somewhere. We can maybe add some kind of background to it so it looks better on the ground. But for now I think it looks good enough when we're walking if we run the game. Yep, there we go. We can see the item and we can walk over it. But don't worry, we won't have the ability to actually walk over it. So now we have the armor. We can even make it bigger if we want. I think that's overkill. So 2.52.5. Yep, there we go. Let's add a bit of rotation to it. So, oops, 2.5. Let's add a bit of rotation. There we go. So there's an armor laying on the ground. We're going to add a component, the item manager. And as you can see right now, this is the item type we can choose. If it's an item, weapon or armor. Obviously it's an animal. Now we need a name, so we're going to name it the silver armor. We need a description. This will defend from monsters. We are going to need a value for it. So let's say it, it's worth 15. We need the item sprite, so we can we can drag this one. Can we, can we drag this one? Yep, there we go. So the item image is now available. How much does it affect? We don't want to be actually using this and we can even move it down a bit. So I think if we move this down, It's better. So because it's not any kind of item that we can drink. So we're not going to actually be using it. We're not going to be using the amount of fact. We are going to add a armor defense you can start to create and some kind of condition that allows us to use these specs instead of the other ones. But I don't think it's worth the hassle for now. Of course, when later on you're creating your own game. Of course we shouldn't have all of these available. So what's the armor defense? Let's say it's six. These are just some kind of weird arbitrary numbers. Now next we are going to add the acts. So we're going to add acts in here. Or you know what? Why don't we just duplicate the armor and we'll move it up and we'll change the sprite to an x. So there you go. This is an ax, say weapon. It's called the silver x. This will kill demons and monsters because we are a daemon. Is a daemon a monster? I'm not even sure what's the value. I think axis are cheaper than armor. The items is sprite, is the ax and the difference 0. Or you can even have some kind of defense for the weapon. But as you'll see later on when we build our battle system, we won't be taking the difference into account when attacking. If we have the ax and the weapons dexterity, let's say it's nine. Okay, save that. Great. Now it's time for a challenge. And your challenge is going to create the rest of the items. So create the rest of the items. What kind of items I recommend that you add another armor and another x. Something that's different may be gold axis. It's a good idea or you can add some kind of shield. We have shields. So two types of sorts, two types of armor, two types of motion. So we didn't add any potions. You'll need to add a potion. And I'll just set sorts in here. It can be accessed, it can be anything you want, and you can add any other item you want. You can add other attributes to your items. So if you think that there are more things to items than just the things that I've mentioned. For example, you can add bleeding effect. So if this, Let's say weapon thus dimensions, you can add the bleeding effect after all, after the certain amount of damage and so on. So with that said, pause the video right now and go add the rest of the items. Okay, welcome back. So we'll name this the silver acts and the armor will be named the silver armor. And let's go ahead and add a golden x. So this will be a golden axe. We're going to find a golden axe. Is this a golden axe? Yep, There is. This is a golden x. Let's close down. Let's move the golden axe a bit. And I think these are just a little too big. I don't know. Maybe we'll make them a bit smaller. So the golden x we are, make sure it's a weapon. It's called the Golden Axe. And its description will kill monsters faster. Faster. Valuing coin of course, is going to be double, maybe even 25. The sprite is going to be the x2 and the acts. And here X to the amount of effect we don't need the weapons dexterity will be 18. And there we go. So this is the golden axe. Let's get some golden armor if we have any. So I don't think we have any gold armor. I think all that we have is oh yeah, there we go. We have some golden armor. So silver armor. Gold armor. Copy that, paste it in here will defend from monsters. Butter. Value will be 35, where we'll change the sprites in here and the difference will be 19. Save that. So let's move this. And here I think I will make them a bit smaller. I mean, look how big they are compared to our gym, the right here. And finally, we need to create the two portions. So I'm going to replicate the golden armor. I'll put the portions in here. This will be the HB ocean and it's going to be of type item. It's going to have the name. So why did it not change HP potion? Thank you. Hb potion, this will give you h be the value in coin. I'm nano 7. And let's see where that is. So where are our portions? There we go. Sprite, sprite and amount of effect. So it's going to affect the HP, the amount of effect. Let's say it gives us 50 HB and just remove this 0 or something. It doesn't matter. And let's just change the rotation a bit. Duplicate. So is everything right in near duplicate this? And let's move it to the right. This will be the monopole ocean. Delete all of this. It's an item. Y mano potion, name it, this will give you a value on coin. I think it should be 11. And let's find the blue portion that's in here, set it in here. And the amount of effect, I think 15 is good enough. The type of effect as the manna, which save all of that. So as you can see now we have a lot of items and if we run our game, Let's see how that looks. Yep, there we go. So a, there's a potion, we take it. There's another portion. We walk up, yo, there's some kind of armor and here a lot of armor and axes that we can use. And I'm going to right-click create an empty game object, call it the items hit Enter, reset its position, and we'll take every single item and drop it under items will also change the scale to 1.8 by 1.8. Let's see. Yep. There you go. I think these portions are now much more logical. They are smaller and they seem like something that would fit on top of our gym edema and things that he can hold in his hand. I mean, look, how cool would that be? That x is still big but no worries about that. So I hope you enjoy it and I'll see you in the next video where we will be creating our items menu.
55. Items Window: Welcome back, my fellow game developers. In this video, as you can see, we've created an amazing looking items window. So you'll see right here that we have for right here you'll see that we have the item's name. We should change this right here. It will change automatically. We have two buttons so we can either use an item or discard that item. And we've also added a small square in here and arranged a couple of items. And I've just noticed that the items button, we should have the item's image right here so the amount appears better. So let's not waste any more time and let's get started. Okay, so now it's time to create an items Menu. So what we'll do, so we already have some kind of items menu, open up the menu and here let's turn this on. And if we go to the items panel, turn this on. There you go. So now we have or we already have an items panel that we can use. Oh, okay. So now let's just make it a little bit bigger on all sides. What we're going to do is we're going to duplicate the items panel. We're going to add it under the already existing items panel, and we'll call this the item's description, this curve option. Okay, hit Enter and we're going to make it smaller. So this is where we are going to set the information of our items. So where will it have a name and the item description that we've created? So we're going to go into one of these buttons, the items button, Let's say we're going to duplicate the text and we're going to drag it over into the item's description. And we'll move it down. And in here we're going to write that this is the item name. And obviously we want to set it to the right and maybe Saturday upwards. So let's just adjust this. And again, this is going to be a long video. I feel even though we haven't started, but because every time you are working with UI, it's going to be a long video. So items name, and maybe make this a bit smaller. So there you go. This is kind of the items name, I think. Okay, so item name, and we're going to change this text to the item name text. And we're going to duplicate it. And no, we didn't duplicate, duplicate now and we'll add an here. This is going to be the item, this corruption or let's just call it the, the script or desk and desk. So because we don't have a lot of space in here, we'll just have to do with what we have. We can even make this a bit smaller. So we are going to make the panel of the item description just a little bit smaller, so we have more space to add. Items will move this down. And there you go. So and this is going to be the item Item Description text. Oh, okay, so let's save that. Now we're going to need two buttons. So what can we do with an item once we choose it in here, we need to either use it or to discard it. So we're going to add two buttons in here, right-click and the item's description, or it doesn't have to be in the item's description. Let's go ahead and created outside of it, but still in the items panel. So a button which we will be dragging down here. We're going to call this the Use button and watch sort of background, should we give it? Well, it's the background that we were using. So the UI elements, Let's give that this background set native preserve. Let's say maybe we shouldn't preserve the aspect ratio. We should add our own aspect ratio. This is going to be duplicated. A Discard button. So discard button, and if you are already bored, I recommend the true pause the video right now and just go ahead and continue on. Because these are very basic stuff. So what I'm going to do, I'm just going to delete the text on the buttons. Right-click, Add Text mesh probe. And we're going to name this use. And the text is going to stay the same or right-click in here again at the text Mesh pro. Scarred should have done that before. We're going to set the font, set the color completely black, make it bold. And let's adjust the positions in here so we're going to set this scarred. We're going to make sure that it's in the middle. And there we go, maybe make it a little bit smaller. So there we go, the discard. I think we can even make this button bigger. So let me just delete the US button and work on a single one. Will then duplicated. So we'll make this a bit taller. There you go, a bit wider. So now we can make our text fit and just a little bit more and increase. Oh, nice, that looks much better. So duplicate the discard button. And we're going to move it right next to the button in here. Where's the text? And we're going to set this to use. Okay, so now that the easy part is done, let's start with the heartburn and before I forget, also we need to go to the item description. Duplicate this also, because we want to add the name of the item in here. So we're going to make this way, way longer. So it should be just around here. And we're going to duplicate this and put it down here. This would be the item name value and the item value. And we'll just try maybe to set it to fit into the text, whatever it is. So auto size because maybe the description is going to be too long to fit in here so we don't want it to go all over the place. Okay, so now that the easy part is done, it's time for the hard part. And we are going to create the items box in here. So to do that, we are going to go into the closed the item description and the item panel right-click, we're going to create an empty game object. This will be the items we are going to make it as big as the available space that we have in here. So there you go. And now we are going to add the right-click in here, create or add UI a button. We are going to give it the background of this kind of panel. So just like we have, and we are going to add the text down here. Let's make it a bit smaller. Down here, we are going to 0. This should be a text Mesh Pro, so no worries about that text Mesh probe. And this will be the amount, amount. That's so because later on we'll have items that we can store or stack multiple times. So we can have, let's say five portions of health on the same position. So let's go ahead and set it down here. Size will make the font will type in 99. We are going to make it. I'm not sure what may be completely black, maybe completely white. I'm not sure what should it be. We'll see later on. And I guess this is good enough. Maybe the button needs to be more square. So the, let's see. We're going to set it up here. It should be square. So let's see if it's a free make the width 160. And yet, I think 120 by 120 is a good number. Okay, so we'll move the text a little bit to the right or no should be using the t. Always make sure to use the rec tool when working with UI elements. So by rack tool, I'm in this box right here, or by pressing V T. Okay? And finally, we need to add an image in here. So we right-click. We go to the UI, we add an image. And this image will be the representation of some kinds of items. So it's going to be the item, items image. And we'll just going to add some default kind of image. So let's use the Golden Axe. There you go. So called an ax set native size o. How pulls that preserve aspect ratio? And we are going to anchor it to the all of the sides and here, so there you go. As you can see, we have the item in here. So now the final step is we are going to add to the items a component that is called the layout, the grid layout. We've already covered this grid layout. So we need to make it 120 by 120 because that's what we've said up here. The size of the button should be 120 by 120. You can see it right here. And maybe just add a little bit of spacing or something. So we're going to set this to 0. And now if we hit the button, items button, we are going to duplicate it, duplicated, duplicated. And let's see how many buttons we can add. So I'm going to issue you a challenge in here, and your challenge is to discover the new component. So we've already covered this component, I know, but it's time for you to discover it. Take the time to explore the new grid component and use it to arrange items in a good way. So find what size you want for your items and make sure to change the spacing, change the size of the cells, play around, see how you can organize your items in the items menu. So pause the video right now and go dude, each challenge. Oh, okay, welcome back. So we're going to go to the items 120 by 120. That's my numbers. You don't have to follow my numbers. So I'm going to add a bit of space in here and a bit of space like that. So how many items do you want to have? And I think I want to make them actually bigger. So I think one good number, 150 as you can see, I'm experimenting. I'm not sure what I'm going to use. I just go with the flow, see what happens. So is that enough items or we should make it even bigger. Let's try 200 by 200. No, that's too big. So 170 by 170. This is how you make games, ladies and gentlemen. So there you go. 170 is a good number. And they fit perfectly fine together. So we're going to duplicate again. And you'll see, yep, there we go. These are our items now they are default values. We will change them later on, but now that we have the correct layout, we can delete all of them. And the way you can choose the first and the last one, click on one of them. Hold Shift, click on the last one, hit, Delete. There we go. So now our items many good locking. In the next video, we will be storing our items in the inventory so that we can later on add them in here in the items menu. So that said, I hope you enjoy it. Oh, and before I forget, I hope you didn't commit your changes because we don't want to have all the PNG committed. So I'm going to right-click and ignore everything under assets, items, or even under assets sprites. Ignore everything, okay, now we'll select all of them and the items with artisans manager and created a items and many. Okay, great commit all of that. I hope you enjoy it and I'll see you in the next video.
56. Lists In C#: Welcome back, my fellow game developers. In this video, we are going to be creating an inventory using lists and C-sharp. So when we run our game, nothing special. You just see in here, hey, new inventory has been created because we have an inventory script on the game manager, this will be important for the challenge. So remember, inventory goes in the game manager. I gave out the challenge. No worries. Let's not waste any more time. And let's get started. Oh, case. So he lists and C-sharp. Why are we using lists and C-sharp? Because we want to create an inventory. And inventory has a list of items. And why are we using a list and not an array? I'll explain in just a bit. But first of all, let's go ahead and create a new script in here. So if we go to the scripts, right-click or go to the items right-click and create an inventory. So in inventory, there we go. And let's open up the script. And this keeps happening. Open up the scripts. And the first thing we're going to do is we'll create a private, Private list. And each list will have a type. It's going to be of type item manager and it's going to be an items list. So why are we using an items list and what's the difference between a list and an array. So arrays have a already defined sites. So when we create an array of players, stats and game manager and so on, we already know how many there will be. We can add to that. But whenever we want to remove a from it, it's going to be very hard. We need to discard the empty place that we leave. So for example, let's say we create an array of three places and one of them is removed, then it's going to be very hard to replace that empty space. Why lists are very dynamic and much easier to go through. And we need something where we can remove an item and place an item very fast. We don't want to be bogged down by removing these empty spaces and filling them with something and rearranging everything and so on. So lists are much more flexible than array. So whenever we create a list, we need to instantiate it. So and start, whenever we start our inventory, we're going to go to the items list. And we're going to say that it's equal to a new list of type item manager. And we'll need to add these two brackets and close off with a semicolon. Now what we want to do is we want to make sure that a new list is created. So it's time for a small challenge, and it's going to be to send a message on the console every time a new list of items is created, every time we start a list. So you get it, start the list. And you'll need to use the debug dot log and standard of print. So pause the video right now and go do this small challenge. Okay, welcome back. So debug, we already know how to do this. It's a fairly easy challenge. So debug backlog and the hay, a new inventory has been created. Save that back in our game. Let's turn off the menu for now. Let's run, oh, before we run the code, we haven't added the script. This was part of the challenge I wanted you to test out. I hope you did, I hope you found this error. We need to actually add the inventory somewhere. Where should we be adding it? Well, I think the best place an inventory is in the game manager. Why? Because as we move from script to script, we want to keep our inventory. We don't want, I mean, from script, I meant from scene to scene, we want to keep our inventory and Game Manager is one of the few want game objects that don't get destroyed when we move from scene to scene. So I think, again, Manager is a perfect place to store in inventory. You can also create a separate script or a separate game object for the inventory, or you can add it to the player. But I don't think the player is the best place because let's say at some point we want to kill our player and destroy the object. We want to keep track of the inventory and something more permanent. We will never destroy the game manager. So now that the game manager has the inventory, we're going to run the game. And there you go. As soon as we start the game we have, hey, a new inventory has been created. Okay, great. So now one of the most essential things to use an analyst is to be able to add things to it. And inventory is very important to have a way to add to it. So if we pick up the items, we need to add them to the inventory. So let's go back and our inventory script. And in here we are going to create a public void, add items. And we are going to give it an argument. And that argument or parameter is going to be of type items, manager, item. Save that. Now in here we are going to call the items list and we're going to add the item. Close that. So now what happens? This is a special method of lists. So we call the items, we call the method add items from the inventory. We give it the item that we want to add. And then we access the items list that we have and add an item to it. And the way we access the list or the inventory is we're going to create a public static inventory in stance. There we go and start. We are going to set the instance to this. There we go, save that. In the next video, we will start visualizing how these items will look in our items, men. So I hope you enjoy it. I hope you are committing your work and I'll see you in the next video.
57. Picking Up Items: Welcome back my fellow game developers in this video FOR, and again, I'll just show you, I don't need to tell you what happens. So we get close to the monopolization. There we go. It does self-destruction and we have manipulation has been added to the inventory. How old is that HP portion? The silver armor and golden orange and the golden acts. So as you can see, we have an inventory that actually works with the items that we've created. So let's not waste any more time and let's get started. Oh, so time to start picking up our items. The first thing we need to do in order to pick up a item as a way to interact with it. So what are we going to do while we are going to add a collider? So we're going to check all of these. We're going to add a component and it's going to be a collider. You can choose whether it's a collider, a Box Collider, or circle collider. I'll just choose a circle. So where did that go? Circle collider. There we go. So each one of these items now has a circle collider. You can adjust each of those. For example, you can see that this one is just a little bit too big for the HP, for the potion. For the gold armor. Nope, that's big enough for the x, for the silver x and for the silver armor. Okay, so now that we have a collider on each of those, we are going to make it a trigger. And we are going to go and create a method where we can trigger something whenever we enter the vicinity already know what trigger means. So we're going to create an entrepreneur, enter on each item. So in the item manager, it's the manager of our items. So we're going to create an on Trigger Enter to D. And the first thing we need to make sure of is we need to, first of all, that it's the player that is well colliding with the item. So we don't want anything else to pick up this item. So if the collision.com tag is the player, then in here we are going to go ahead and do a couple of things. So the first thing is we're going to print out the items name. So this item is and we're going to concatenate it with the which one of those and item name. So item name, close that off, save that back and our Unity, Let's run the code and see if that works. So run our game. And now if we move to the manna portion, there you go. This item is demand apportion. This manna is the HP portion. Silver armor, silver and gold armor and the Golden Axe. So how cool is that? We already know which item we are picking up. But as you know, when we pick up an item in a game, that items disappear. It doesn't keep standing there and watching us. So we'll need a way to destroy it. So in order to destroy it, I'm going to issue you a challenge. And your challenge is to self-destruct or self destruction. So create a method and items manager in the item script, this should have been item script that destroys itself. So use it when an item is picked up by the player. And I'll give you a small hint. If you already know how to destroy a game object, pause the video right now and go do the challenge. Not use destroy. Yep, that's it on a game object. So pause the video right now and go do the challenge. Okay, welcome back. So in here we'll create a public void, even though I don't think we'll be using it anywhere else. But let's just keep it as public, will call itself destroy. And in here we are going to destroy the game object. Save that. And now after we pick up the item, we are going to South destroyed. There you go. Save that. Back in our game in here. Let's see if that works. So now we should see, for example, manna potion, and then that monopolies should disappear. So we pick it up. There we go. Man abortion at disappeared. The health and everything we can pick up and all of that disappears. So great we are on our way to creating an incredible items system and inventory system. But there is still one little thing that we need to do and that is first of all, we can remove this, comment this out. And in the inventory will also comment this out. We no longer needed save that. Now we need to actually add that item to our inventory. So what we'll do is we'll save everything in here, will go into the add item. We'll just print out the hint here, something just to keep track of everything and make sure nothing is going wrong. So item I am and to do something else, item dot item name plus the has been added to inventory. Save that. And what we can also do just like we have the length of an array. We can also check for the items list count. So we count gives us the size of the test. And what we'll need to do in here before we cells destroyed. We are going to access the inventory. We are going to access the instance and we are going to add an item at items. And the item that we are going to give it is this. So save that, and let's see if that works. So back in Unity, we are going to run our game and we're going to check if we are adding items so we pick up the mana. There you go, man, abortion has been added to the inventory. Then we have the HP portion has been added to the inventory and you can see that the count is two. The armor, the, what is it? The silver acts, the golden armor and the golden acts. So as you can see, we've created a way of adding things to the list, the growing it, and that's it. In the next video, we are actually going to be displaying the picked up items in our inventory. So I'll see you then. Don't forget to, to commit your changes.
58. Updating Items in Inventory: Welcome back, my fellow game developers. We're not doing anything fancy in this video, we are simply laying out the groundwork that we are going to use to spring up to the next video where we are going to be displaying all the items that we are picking up. So we'll just get a reference to a couple of things. We'll briefly talk about instantiation, and we are going to also create a method that returns lists. So let's not waste any more time and let's get started. Okay, so time to display the items that we are picking up. How are we going to do this? First, let me turn on the menu so we can clearly see what's happening. So what we want to do is every time we pick up an item, we want to create a new item slot in here. And we don't want to have all the item slots available in here and then turn them on and off. We want to actually instantiate them whenever we need them. So we are having a bit of a different approach than before, especially when we were creating character and 4, where we already have everything in here. We want to create something different. We want to actually instantiate each item as it's being picked up. So how are we going to do this and what's even instantiating? Well, we won't go deep into instantiating in this video, but let me just give you a small overview. The way we instantiate something is we have a prefab of it somewhere stored in our assets. And every time we want to create something that's similar to this prefab, maybe with small differences, we can instantiate it. So first thing, as we know, we need the prefab reference. We need the parent. Why parent? Because we want to instantiate the items inside of the items. Let's call it the items display panel. So this play panel, so we need a reference to this item display panel. So we can create items, buttons, which will be our prefabs inside of here. And because we've already created a grid layout, they will be laid out very neatly and our menu. So I hope it's not too confusing. I just wanted to lay out the groundwork for the next two videos so we don't get confused. Let's get started. First of all, we are going to create a prefab. So NR prefabs in here. Let's go ahead and drag the items button. So this will be what we will use to instantiate and we'll also get a reference to it. So let's go ahead and open up our scripts and the menu manager, where is it? So in Menu Manager and haven't noticed how many scripts we already have, our gain is really taking shape. So whether that's small reminder, let's get a reference to the item slot container. So we're going to create a serialized field. It's going to be of type game object. This is the container of our items. So item, slot, container. This will be the, this one the display item. So where is it? So it will be the items display panel. And then we are going to create a second serialized field which is going to be of type transform. And it's going to be the item slot container parent. Okay, so what I can say that the items slot container will be the prefab that we've just created and the parent will be the item display panels. So just to avoid any confusion, just like I confused right now, this will be where we said the parent, this will be the container which we will be instantiating, will see all of that in just a bit bare with me. Next, we'll need to create a method to display our items every time we pick them up in Menu Manager. So in here, we'll scroll down and after the Stats menu update will create a private void. Update items, inventory. And for now we'll just leave it blank because before we do that, we need a way to get a reference of our items. If we look in the inventory, you'll notice that the list of items is private, so we need a method in the inventory to be able to get them. So the way we do that is by issuing you a challenge and your challenge is to create a method of type list. So create a method that lets us access the list of items. The method should be of type that returns a list, a particular type of list, and should return the items list that we have. So pause the video right now and go ahead and create a method that gets us the items list. Okay, welcome back. How did you get all of that? And I'm not sure we'll be using update for now. So I'll just remove it if we do need it, will create it later on. So this will be a public because we're going to access it from the front scripts. It's going to be of type list. You already know that, but what type should it be? It should be of type items manager because we are getting these items list and it's going to be called the get items list. It doesn't take any arguments, and all it does is it returns the item list. There we go. So what happens now when we call upon the instance of the inventory? We access the method get items list and it returns to us this item list. So back in our menu manager, where is it? We are going to be using it in here to make sure that we have all of them. And the next video we'll be adding the slots from the code as we go on with our game. And maybe before we do that, let's just go and the canvas That's scroll down. Let's see. There we go. The item slot container. This should be the Items button. And we transform will be the items display. And you might be wondering, why is it of type transform, because if we click on the Items display, you'll notice that it doesn't have anything other than the transport. We may even have to change it to Rect, Transform. It's a different type of transform that is used only for the items or the game objects in UI. So with that done, I hope you enjoy it. You won't need to commit your changes just for now in the next video. So I'll see you then.
59. Displaying Picked Up Items : Welcome back, my fellow game developers. This is a very exciting video because when we pick up items, if we go now to our menu, we go to stats items. There you go. You can see that we have all of our items displayed with the correct sprites and how many we've picked up? No, not represented by a number, but you can see that we have three bottles of health promotion and so on. So this is a very exciting video. It really puts everything we've worked together with. A bit of a complicated code may be, but we'll learn everything step-by-step and you'll understand every single one of those steps. So let's not waste any more time and let's get started. Okay. Time to get to the hard part. It's not too hard, but it's kind of new. So what do we want to do? And our coding here, we can see that we want to update the items in inventory. So what we'll do is we will go through each of the items in the items list. And we could use the for loop, but there is a much better and efficient way of accessing each item and a certain list. And that is the foreach loop. So let's talk about the for-each loop, a very central to. So it allows you to go through each thing in a collection of things of the same type and an array or list, it doesn't matter. So this is the structure we write for each we set the type, we create a name in kind of things. So it will be, they should of course be the same type. So this will be the list that we were going to access. So for example, in our case, this will be the items list. This will be any variable that you want to name so we can name it items. And it will be of type item manager because we are accessing item. So then when we access or when we go through each of the items in that list, we can get the thing or the item. We can use some method on it, or we can send it to some other method or execute any other things that we want with it. So let's go ahead and implement a foreach loop. So we are going to write for each, we're going to open up this small brackets and it's going to be of type item manager. It's going to be named item. And we are going to be looking in the inventory. For instance, dot get list. So get items list. So this is the method that we have created earlier and here, so there you go, Get items list. So what are we going to actually be doing in here? Well, what we want is to instantiate the item slots that we set up right here. So we need to create new buttons, hour slots for the item every time we have a new item in the inventory. And if we go in here, I will show you what instantiating means. So as you can see, there are many declaration of it in the unity dogs. And one of them, and the one that we're going to use is this one which allows us to set a certain parents for it. So it will become a child of another object or it's going to be under it. And why do we need that? We've already covered this in the previous video. We want the items created to be the children of this items display panel so they get laid out correctly using the grid layout. So that established, let's go ahead and use this one, the one that uses the parent, and we've already set up the parent in here. Where is it? So there you go, the items slot parent container. So how are we going to do this? Well, it's going to be first of all, of type Rect Transform. So Rect Transform, we've already said why it's direct transform, but we'll go over it again so you can see right here that it's Rect Transform. So in here also we are instantiating a wracked transform, not just any transform. So back in here, Rect Transform is going to be the item slot and it's going to be equal to instantiate Item slot container. And this is the prefab that we've set up. Now we need to give it a parent which is going to be the item slot container parent. And if we stop right here, you'll notice that we have an error because we want to instantiate a game object into a Rect, Transform. And that's why we are going to access the component. So we'll get the component of the wracked transport of that object. So I hope this makes sense. What are we doing in here? First of all, we are instantiating the item slot container. And setting the parent as the item slot container parent. We've already set up these two variables in the previous video. And then we are accessing the component of the Rect Transform so we can use it later on, maybe if we do need it. So I hope that's clear. Let's save all of that. Let's go back into Unity, and let's go ahead and turn the menu off. With run, our game will pick up a few items. So 1, 2, 3, 4, 5. Work ahead the menu. We'll go to Stat, go to items. And we don't have anything to display because how many times do I have to make this error before I finally get it, we end buttons need to actually call this update items method. So an items will add one here. Canvas, which function do you want to call? I'm going to update in the menu manager, where is the update? Did we make it private or case? So let's make it public. Say that back in here. And now we can extra money manager and update items in inventory, save that, run our game. And now when we pick up a few items, there we go. So now we hit the M key. Stats go to items, and there you go. So we can see in our console that we have five items. And in here you can see that we have six. That's because we already have one of the buttons established. So how are we going to avoid this? And especially if you've tried this on your own, you'll notice that something very weird happens when we add all of those. We hit the M key items, items, items, and you see that every single time you are increasing. Why is that? Because if we go back in the code, you'll notice that we are going through each item and then we are instantiating the slot container again and again and again and adding it to the slot container parent. So how are we going to avoid this? Well, I'm not sure how we can do this. I've done a lot of research, so I think this is going to be your job to do. So you are going to destroy slots before we instantiate them. So you are going to use your newly acquired knowledge to delete or destroy item slots before updating them. And you'll need to go through each item slot in the item slot container and destroy. So with that information, pause the video right now, goes through all the items slot and the slot parent and destroy them before we update the inventory. So that non, pause the video right now and go to the challenge. Oh, okay, welcome back. I hope it wasn't too hard. So what are we going to do before we update everything in here or before we instantiate? Maybe you've done it in a separate method. That's not bad. But we can do it in the same method. We are going to go through each transform item slot and the item slot container parent. And what we're going to do is simply destroy the item slot game object. And we're accessing the game object because this is a transform. So because the item slot container parent contains types of transform, we are going to destroy the item slotted game object. So how will that work? We'll go back in here. We're going to run our game. We are going to pick up a few items. And now you'll see that we have five items. If we go stats items there you go 12345. And that's because we are always destroying the previous ones available. So back-end stats items, you'll notice that we no longer have the error, but there is a slight problem. And that is the images are still the same, so we have the default image. So to fix that, we'll go back into our code and where we instantiate our item slot, we are going to create a variable which will be of type image. It will be the item image. And it's going to be equal to the item slot dot find. And we are going to look for the image inside of the items slot. Now, what is find? Let me show you. Find. There it is. It's finds a game object by name and you always use it on a game object. So you can see that game object dot find. So what we want to do, so make sure that you take this in and open up documents so you can see it clearly. What we want to do is go to the Items button right here and access the items image. So we are going to copy this because it's a string reference and it looks at through by name. We are going to paste it in here. And we are going to get the component on it, which is of type image. So I recommend that you use this dot find very sparingly because it can cause a lot of errors, especially if you sometimes change the name. So if we change the name items image from under the item slot, it's going to cause a lot of errors. So I hope you understood what we're doing in here. We access the item slot that we've created. That's why we made sure that it's a variable, so we can use it later on. We find the image which is named items image. We get the component image. And now we are going to set the item image dot sprite to equal the item because we are going through each item, remember, and our inventory items image. So we're going to save that, go back and our game, we're going to run the code. And if we pick up a few objects, they should have the correct image being displayed. So static images, there we go. How cool is that? So we have created a really good looking inventory, but there is a slight problem if right now I pick up a second bottle of health. So items, HP potion. Let me duplicate this. So we'll add it in here. We've added and here we're going to run the code. So now I pick up 1231 of the health potions and a couple of other items. If I go stats items, you can see that we have three health potions. Now, this is not a mistake. Everything is working fine. But if you played RPG games, you'll notice that potions and other kinds of gems are sometimes stackable. So we have this number right here should represent how many portions we have. Maybe swords and axes and armor shield and so on. They don't need to be stackable, but potions do need to be stackable. So we're going to tackle this problem in the next video and make sure to stage all of your changes and the source string. So I hope you enjoy it. I hope you're enjoying the course. I hope you liked me as an instructor. If you do, again, I'm going to remind you, do a plug-in in here. Leave me a review at what helped me out a lot. Thank you.
60. Stackable Items: Welcome back, my fellow game developers. In this video, we are going to be stacking items on, on top of each other. Now, even though Jimmy the demon can put axes in his pocket, he has large pockets to add bosons all together. So now when we run our game, you'll see that if we pick up one of the axis and shields, I mean Armen, we can also pick up multiple of these potions. So you'll notice we picked up three mana potions and for HP portion. So when we had, um, stats items, there you go. You notice that we have one acts of each and one armor of each. But when we look at the potions, we have 43. They are stacked on top of each other and not in different slots. So let's not waste any more time, and let's get started with stacking items. O, k. So some items should be stackable, others shouldn't. So coins, oceans, and so on. All should be stackable. Plates of armor, helmets, swords, and so on shouldn't be stackable. So let's implement this in our items manager. We are going to go into the items manager. And in here we are going to add two new variables. The first one is going to be a public bool and is stackable. So if this one is true, we are going to add it a bit differently in the inventory. And another variable that will add is going to be an integer and it's going to be the amount. So let's say you throw a portion of health, you can set the amount to be two or three, or five or 10. Okay, so with that done now we need to create a special method in the inventory to add them. So we're going to make sure that we can check for an amount every time we add an item. And currently we're going to remove the printing or maybe, you know what, let's just remove it or let's keep it as a comment. So we'll comment it. You know what it was to remove it, we're going to remove this one and this one. And now we are going to check and the items. So first of all, if the item that we are looking for is stackable, then what we're going to do is loop through each items. Manager will name this the item. And then Tory and V items list. And then we are going to check if the item in inventory list dot item name is equal to the item that we are trying to add dot item name. So basically what we're doing in here is checking if we already have that item in the inventory, we're going to go to the items in the inventory, will access the amount. And we are going to increase it by the amount of the item that we're trying to add. So what's going on in here? We are first of all checking if it is stackable. Then we're going to look through our items in the items list. And we're going to check if one of these items is equal to the as the same as the item that we just picked up. And if it is, then we are going to increase the amount of the item in the inventory by the amount of the item that is given to us. So let's say we already have two health potions. We pick up two more health potions. It will increase by two, so we'll have a total of four. And finally, if it's not stackable, that will simply going to add the item and the list. There you go. Oh, okay. Correct. But what will we do if the item is stackable but hasn't been added yet. So it's the first time that he is getting added to the inventory. We're going to create a Boolean in here that will keep track of that. So a boolean item already in inventory, and it's going to be equal to false just by default. And if it's available inside of the inventory, we're going to set it to true. So item already in inventory equals true. So that's established. But if it's not, then we'll create a condition in here that's going to be if the item isn't already in the inventory. So you'll notice that I have this exclamation mark. So if the item in inventory is false, that means it wasn't found in the inventory and the slope right here. Then what we're going to do is simply go to the items list and add that item. As we normally do. There we go. So what's happening in here, as you know that in here and this for-each loop, we are looking through all the items and checking if we have that item inside of the inventory. And if we do find it, we increase it by the amount that we are getting. And we are setting the items already in inventory to true. So this condition does not access, or this, this condition in here is false. Or the entire condition right here with the exclamation mark is false. So we don't add the item to the list. We simply increase it by the amount. If we don't find it, then the item in inventory stays false, then this entire condition with the exclamation mark is true. That means we need to add the item. So let's save all of that. Let's go back in our game. And now when we pick up all the health potions, we shouldn't see three. We should only see one of them. So now we pick up these. We go to stats items. So now let's go back and do unity. And we should see that on the silver armor we have is stackable and the amount. So we're going to go to the HP portion, make sure it's stackable. We need to add to all of these that the amount is one. We should have put it as a default whenever we create any object, you need to make sure that at least there is one and the HP portion as one and so on. So the HP portion, all the HP portion and all the portions in general are stackable. So we're going to save that. And later on we are going to be pre-fab in all of our items. So this won't be a, such a big hassle. So we're going to actually, it's a good idea to preform them now. But let's continue on. Let's run the game. We'll do that in just a bit. So we run the game, we pick up a few items. We check the items. And as you can see, even though we've picked up three potions, we only have one slot of them. Now the next obvious step is to represent that there are three potions and not just one. We'll need to access the text right here. And it's going to be part of your challenge. Your challenge is to update the amount text. So first get the items are mounted text, you will need to access it. Then check if we have more than one item. If we do, you'll need to display it else. We don't really need to display it. So for example, if we have a one autumn, we don't want to put in there that we have one order. It's enough to just see the image. So we need this condition to check there are more than one of these items. And I'm going to give you a small hint. You need to make sure to convert the amount to two string, because when I was creating the game, I had this error and it took me a long time to figure out, so I thought a Hinton here would help. And with that said, pause the video right now and go to the challenge. Hey, welcome back. So part of the challenge was to find where do we actually need to do all of this? And we'll need to do it, of course, in here when we are updating the item's inventory. So we're going to create a variable in here of type text. It's going to be the items amount Next, and it's going to be equal to the item slot. And we're going to find in here the amount of text. So if we go back, we find the amount text, we copy it because it's a string reference we've pasted in here. We are going to access the component tax, and let's go ahead and access that text. And before I continue on, I remember I did a couple of changes in here to the text much Pro, so it's no longer the medieval. And I just changed to the Liberation Sans as the F made bold and added a couple of things in here. Oh, no extra things. Just changed it up a little bit and increase the font size just so you know, if it's different from your font, actually, you needed to take the time and set everything up when it comes to you. I so with that done, let's go back. Save that. Now we're going to check if the item dot amount is greater than one. Then we are going to set the item amount, text dot text to be equal to the item dot amount. Dot toString. And you'll notice that I didn't add any brackets. And I'll tell you why in just a bit. And if the item is not greater than one, then we'll simply set it to 0 so the item, amount text, the text will be equal to an empty string. So where are the brackets? Did you lie to us that we never have to use them? Well, no, because we are simply using a single line in the conditional, we are trying to implement a single line of code. We don't need to add the brackets. Now, this squiggly brackets, now, if it relaxes you more to add them, then go for it. This is just to save a bit of space and a nifty trick that I wanted to teach you. So we're going to save all of that. We're going to go back into Unity. We are going to duplicate the manna potion, duplicate that. And another one here, duplicate that, I add another one here, save that to run the game. And now when we pick up the potions, pick up the portions, backup the items. We hit the M key, go to the items and we have an arrow. And that arrow is telling us that when we are trying to update the items dot amount toString, not getting a reference. So object not set as an instance of gaze. So obviously, obviously, obviously you need to go to the Canvas. And where is the amount of tax? The tax. And it's because we need to make sure that it's a text Mesh probe because we see, because I remember that we copied this or we changed it to a text Mesh Pro. It's no longer a regular text on a button. So instead of text in here, make sure that it's text Mesh pro GUI. And I hope that during the challenge you didn't fall to the same mistake. If you did, no worries, you can see that it happens to the best of us. If you didn't, I congratulate you. You have taking the next step, young grasshopper. So we save that. We go back and our game, Let's run this. And I believe that there is no longer any errors. So you can see that we've picked up two portions of health and three portions of mana. We go stats items. There we go. So we have one x. We don't need the numbers because we have one of each and they are not stackable. The stackable items you can see that have a number down next to them. So how cool is that? Our inventory is really taking shape. And finally, a small step. We're going to create a folder in here for the items. And we're going to set all of the items, not the ones with one and twos next to them on the the original ones. And why am I not able to add all of them at once? To add them one by one over x, golden axe and so on and so forth. So we're going to be using these pre-fabs and order to add items. So for example, HP portion. I need to be in the scene. Hp portion. There you go. We've added another HP potion and we can change everything about this HP portion from here, from the prefab. So I hope you enjoy it. I hope you're committing your changes and I'll see you in the next video.
61. Selecting Items: Welcome back, my fellow game developers in this video, when we run the code, when we pick up a couple of items. When we access the items, if we click on one of them, noticed what? Notice what happens in here. There you go. So now we know this is an HP portion. What does it do? This we'll give you HB. This will give you mana. This will kill monsters. This will kill monsters faster because it's a golden axe. This was a silver acts. So let's not waste any more time and let's get started. So currently, if we pick up a few items, you'll notice that when we go to items, if we click on them, nothing happens. We still have the item name, item description, or empty, and we can't use anything. So basically it's a worthless item list. We're going to change that. So first we're go into the menu manager and op here we're going to create a public text item name. We're going to create a also add to it the item description. And we'll also going to create and here a instance or we already have an instance. So that's good. Save that. Now we're going to go back and unity, wait for this to compile. And we're going to create a script that handles pushing one of these buttons. So we have the Items button. We want to create a script to handle what happens there. We could use the onclick. We will use the onclick, but we want to create a script. So we'll go into scripts, will go into items. Do you think items management is a good place to create this? Yeah, sure. Why not so well, create a script in here, we're calling the item button. Hit Enter, wait for this to compile and we'll go into the Prefabs items or prefabs item button, and we're going to lock down, go to the scripts and add the items button. And so there you go. So Items button, save that. Open up the items button. And what are we going to do here? Well, we're going to create a method that presses or case. So here we are in the items, the script. We only need one single variable for now, and it's going to be a public items manager and the item on button. So this will represent what item we have on the bottom. So now the next step is to create a method that gets called upon every time we press the button to set the item stacks or items name and the menu manager and the item's description. And it's going to be part of your challenge. Your challenge is to create a method to press. So an Items button, create a method press, use it to access the memory manager and set the item name and description based on the item on the button. So pause the video right now and go do the challenge, 0, k. So let's delete the start and update for now. I don't think we'll need them. We'll do later on. If we need them, create them. We're going to create a public void progress method. And in here we'll access the menu manager dot instance, dot item name, dot text. And this is going to be equal to the item on button, the item name. And we'll also set this exact same for the description. So instead of item name, the item description, and the item description, we will save that. And now let's go into the menu manager. Let's scroll down. Where do we set up the upcase or here where we update. After we finish updating, we are going to go to the item slot. We're going to get the component. And that component is the item button. We're going to access in here, the item on button. And it's going to be equal to the item which we just added. So I think a better way would have if we set this to private and then created a method to get access to this item button to set it. That would have been probably better. But for now we'll just use this as a public. No worries about that. So where were we and the menu manager? There we go. Item slot get component. We access the script item button, which is a component on the item slot. We access the item on button and we set it to be the item that was just added in the inventory, the list. So now if we run our game, if we go into our Canvas, open up our Canvas, open up our menu. And by the way, Unity just crashed on me. So we're going to, where's the menu, the items panel, the item description. So we're going to lock down the canvas. What do we need? We need the item name, the item description. Let's see. Is this the item description? There there's this under a year, so the item name, text, et cetera. So how many times would I make this mistake of text? Mesh pero Gui? So you're probably frustrated that I keep doing this, Michael, you need to set it in your head. We are using text Mesh Pro. Save that. So now I know that I have two problems to work in. First of all, make sure to always set the text Mesh broad, not text, and to always set the elements in the inspector. Until now, I've fixed this problem, fixed one of them at least. So we save that. We run our game. Oh, okay, so before we continue, I just noticed that we have the value. We should have set the value. So what's this deleted? I prefer the description. So we need the values and not the regular text. So we said the value, description value. We save that. We run our game. We pick up a few potions. And again, there is one more thing that we need to do. If we go into the Prefabs and the Items button, we remove the lock so we can see it clearly. We need the onclick to be V items button script. And in the Items button we call the press. So save that. And now everything is set up. We can pick up a few items, pick all of these up. We'll hit the items. If we click on one of the items, there you go. It's a golden eggs. This will kill monsters faster. Let me make this bigger so it's clearer. This will kill monsters faster. This will kill monsters. This will defend from monsters better. This will give you HB, It's an HP potion, and this is a monopole ocean. This will give you money. So now these buttons actually do things. And the next video we will see how we can use the discard button in order to discard the items. So I'll see you in the next video.
62. Discard Items: Welcome back, my fellow game developers. In this video, we are going to be picking up the items. And when we hit the M key, we go to the items. If we choose one of them and discarded. There you go, you'll notice that it disappears. We've made a bit of tweaking on how the items get destroyed. And there you go with destroy all of the items. So let's not waste anymore time that I say destroy. I mean discard all of the items and let's get started. Oh, okay. So to discard an item, we need to keep track of the act of item that we just clicked. So we're going to do just that. We'll go into our menu manager, and in here we'll create a public items manager. And the active item. There we go. So now we need to go into the items button. And when we press will go to the menu manager, will access the instance, will set the act of item to be equal to the item on the bottom. Save that. Now what we want to do is create a method that discards the act of item. And I'm going to issue a small challenge. It's not what you think. Create a method to discard an item and init, print out the name of the item we just discard that. You'll need to make sure that you apply it to the discard button, which is something that I keep forgetting. So please, you do that for pause the video right now and go to the challenge. Okay, welcome back. How did you get on with that? We will scroll down to the bottom. And in here we'll create a public void. Discard item or simply discard. It doesn't matter. So in here will simply print out the active item, dot item name, item name. Save that. We'll go into Unity where we'll access the where is it? The discard button? Why do we have a Discard button one? Did we just duplicated and leave it there? So the menu turn that on. Let's see, Discard button, Double-click. Oh, okay, so let's change this from this cart button to use button. Now in this cart button, we are going to scroll down. We're going to add an on-click. We are going to drag the canvas. We are going to access the menu manager. We are going to discard the item, save that, run the game. That's turns off on stats ICT 0. So who, who haven't even picked up any items. So we'll run the game again. We'll exit will pick up a couple of items. There we go. Hit Enter and stats Items. Click on one of the items, discard. There you go. We're discarding the silver acts were discarding the silver armor, discarding 10 potions, and discarding the HP. So we are getting the active item correctly. The next thing is to actually start from moving it from our list. So we'll go into the inventory, will create a method in here that's going to be the add item. We're going to create the method public void and we'll remove the art. So remove item and it's going to take an argument which is going to be the item manager, type item manager and the item that we're going to remove. And in here we'll do a couple of things. We can just simply start removing from the item list. We need to make sure first of all, that it is stackable. If it is, we just want to remove one of them, not all of the Ahmad or not all of the items. So if item is stackable, then we're going to, first of all, create a variable in here of type item manager. And it's going to be the inventory item. And it's going to be equal to null. And you'll see why we're doing this in just a bit, okay, so everything is fine. We're going to loop through all the items. And we're going to make sure we look through the items list. And we're going to check if v item in inventory, which we are getting right now. Dot item name we've already covered this is equal to the item two equals signs because we are comparing to the item, the item name. Then what we'll do is the item in inventory, the amount the amount the IntelliSense is not helping me at all. And we'll just remove one. Or we could have simply written in here minus minus. So this removes A1. And then what we'll do is we're going to set the inventory item, which we created up here to be equal to the item and inventory. And why are we doing that? Well, because we want to check after we finish the for-each loop, if the inventory item is different than null, and the inventory item is less than dollar amount, so that amount is less than or equal to 0. Then what we'll do is we're going to remove the item. So the way we remove as we access the item list with up and remove, and we access the inventory Item. So what we're doing in here is we are creating this variable to keep track of the item that we are removing. If we remove one, let's say the amount gets to 0, the inventory item, then we check if it's different than null and the amount is less than or equal to 0, then we will remove the item. Otherwise, we will simply remove the amount and just keep track of it for later on. And else if it's not stackable, then we'll simply remove the item. So else, if it's not stackable, item, list dot remove the item, save that. Now we'll go back into Unity. Okay, so currently, when we run our game, there is a slight problem that we didn't talk about. So when we pick up all the items, we hit the M key, we go to the items, we click on one of the items. If we look on the Items button in here, you'll notice that the active button or the item on button is missing. The same holds true if we go to the Canvas and look for the active Item. Now you might be wondering, why is this happening? Aren't we writing the code correctly? Is the something wrong with adding inventory? Is there something wrong in the Item Manager? Yep. If you thought about the last one, the problem is the item manager. So what's happening in here? Every time we are picking up one of the items, we are destroying it. You can see it right here. So when we destroy the item with destroy the game object and there is no more reference to it. So instead of destroying, we are going to set the active at 24. So we're going to set this, the setback. So we're going to set the game object dot set active to false. Save that. Now back in our game, we're going to run. And now you'll notice that the items instead of being destroyed are simply going to disappear, but they are going to still be in here available to us. So we, we pick all of that up. We hit the M key, go to the items and you'll notice that now, there you go. We have the potion and the, all other items. If we click on the golden axe and the canvas, we have a reference to the Golden Axe. So now when we discard the items, the final one we discard, it will disappear so well, everything else. And you'll notice, there you go. So everything is disappearing. Everything is working correctly. So with that done, I'll see you in the next video where we will be using the items and not just discarding them. So I'll see you then.
63. Using Items: Welcome back, my fellow game developers. In this video, we've implemented the use of a button of the US button actually. So now when we go to items, we choose one of the potions. If we look on the player, we use the potion, but wait a second, the current HP is still the same. If we try it again, whoops, the current HP still the same. But if we choose the healer, you'll notice that when we look at the current model, which is 3, if we add a bit of manner to it, there you go, you can see that it's working but not on the correct player. We'll fix that later on, but for now it's time to implement the use button and our icons menus. So let's not waste any more time and let's get started. Okay, so it's time to start using our items. And the first item that we're going to use or items that we'll use are the portions that we have for Adding Mano and adding HB. So for that we need to methods and player stats that add mono and HP to our player. And that's going to be part of your challenge. Your challenge is to add manner and HP. So make an instance of the player stats script. And it also create two methods. One to add mono and want to add HP. Both methods should have an argument or a parameter passed to it on the amount to apply the amount to the current HP slash mono, and make sure that the current HP and mana never goes over the max HP manner because we don't want our player. Let's say if the maximum HP is 100, we don't want the player to have, let's say, 110 or 120 when HP is added to his health. So with that said, pause the video right now and co-create the methods. Okay, welcome back. So in here, let's go ahead and create an instance. So public, static, instance, ops, player stats, instance. And start. We're going to set the instance to this, save that. Now we'll scroll down and in here we're going to go ahead and create two methods, the public void, add HP. And in here we're going to take an integer parameter which is going to be the amount HB to add. And let's go ahead and start typing in here. So what are we going to do? The first thing we'll do is we'll get the current HP. It's going to be plus equals. So we'll add to it the amount of HP to add. But we'll need to make sure that the current HB, so current HP, if it goes over the max HP, then we're going to set the current HP to be equal to the max HP. So that's all that we need to do and will do the same in here. So we'll duplicate this one. And this will be the add mana. This will be the amount manner to add the current mano. A mano to add current Mano. If it gets greater than the max Mano, then the me just copy this, paste it in here, copy this, paste it in here, save that. So now we have everything set up. Now we're going to create a method to use these items from the items manager script. So in here under the update or you know what, let's just delete the start and update because I don't feel that we'll be needing them soon. And in here we're going to create a public void Use Item. And in here the first thing we'll do is we're going to check if the item type is equal to item, type dot item. We are going to check if its effect type is equal to the effect type of effect HP. Than what we'll do is we'll call upon the player stats. We'll access the instance, will add HP and we'll send it the amount of effect. So there you go. The amount of effect else-if its effect type is equal to effect type dot mono, then, oops, I meant that this one should be in here. So the if condition is not whether it's an item or not, it's on the whether it affects HP or mono. And I just added an else-if and not just an else because maybe you would like to add other oceans that increased dexterity. And so on. So it's better to use else if in this context. So we're going to add a player stat, the other instance, Madonna, and the amount of effect. There you go. Save that. And finally, what we need to do is we need to call the US item from the menu manager. So a free go to where is it? Where's the menu manager? There we go. So in Menu Manager, we have the discard item. Now we're going to create a public void Use Item. And in here we are going to check for the act of item. We're going to use the item. There we go. And finally, there is one more thing that we need to do and that is to discard the item. So we're going to call upon the discard item because as soon as we use the item, we want to discard that. So what it does, it will remove it from the inventory using the inventory instance remove item and then update the inventory. So we're going to save that. We're going to go into our game. We are going to make sure that we've saved everything. Okay, so back in our game, run our game. And let's look at the player, will see right here that we have, I've, Where is it? So the players current HP is 0. So we'll pick up a couple of items had, um, go to the items, pick up the health promotion, let's use it and see if the current HP increases. We haven't assigned the button to do anything. Okay, so Canvas, menu, buttons, stop items, use button, click on that, add a onclick at the Canvas, go to the Menu Manager and use item save that, run the game. Now this should be working so we pick up the items, go to amniote items, pick the half portion That's click on the player makes sure that the, there is some kind of effect and as you can see, there is currently nothing. So you might be wondering what went wrong as our code not write as something that we tried to add in here, not working while everything is working. But the problem is, is that when we pick up the items, we hit the M key, go to the items to the HB potion and use it. It's not the player that that's getting affected. It's the healer and PC because it also has a player's stat on it. And if you look closely in here, you can see that the current Mano on the healer is three. If we choose the monopole ocean and use it. There you go, you can see that we've added a bit and again and again. So now we are able to use our potion. But the next step is to actually have a way of choosing which character gets the benefits of using the portion that we have. So in the next video, we'll be choosing the appropriate character to use. The portions and items are. I'll see you then.
64. Adding Character Choice: Welcome back my fellow game developers. So remember when we used to pick up items and not know who can get what while now when we click on one of the items, we tried to use it, whoa, we get this panel right here that opens up and asks us, who do you want to use this on? Whether it's jimmy? Is it Sarah? But we can still do anything about it. We will do that in later videos, but for now it's time to create a panel for the character choice. So I'll see you then. Okay, so how are we going to be able to choose which player gets the potion we want to use it on, or any other item. We are going to create a panel that opens up whenever we click on news. And let's choose between the available players. So we're going to turn back themed menu on. We'll double-click on it to open it up. Make this game window a bit smaller because we have a bit of editing in here to do. We are going to maybe let's say the items display panel. Nope, I think the item description, Let's duplicate this. And in here Let's delete everything, delete that. So now we have the item description, which is a round as big as the original item description. This will be the character choice panel. Let's hit Enter. And in here we are going to have a couple of buttons. So let's go into the buttons in here, get the items button, let's duplicate it and drag it down into the character choice. And let's move it down in here. So we are going to have the option to choose between three players. I think that's the amount that we had. So we'll make this a bit smaller, maybe make it a bit taller for the name. And it's going to be the layer choice, C choice, player's choice. Okay, So player choice. And let's see if we can just make the font a little bit smaller and make it bigger on the sides. So there you go. That's good enough. I think that's a good place to choose the player. Let's make this smaller fate choice, and let's put it in here. Let's duplicate this. So we'll set, this will be the first one on the right. This will be in the middle, and we'll duplicate that again, have the third one in here. And now let's see, it's about 400 by 134. So we're going to add a grid. So we're going to add a grid layout. We are going to set these buttons up. So we're going to expand them on the x, on the y. Let's add a bit of spacing. And let's see. Maybe on the y naught, we don't hit on the wild because we don't have any distance. So yeah, that's about right. And we can move it. We can add a bit of padding from the left. So there we go. Remove the spacing on the right. And that's about how much we needed. Maybe we'll move it down. So we'll add a bit of padding from the top. This was part of the challenge when you need it to explore. So I bet you found the topic, the padding. The padding. And let's see, maybe this should be a smaller on the side, and there we go. So now we have three player choices buttons that we can use. So what we'll do is whenever we hit the US key, we are going to open up this panel and choose one of the available players. So maybe we should change the text in here to say player name. And that's why we need to make it a bit smaller or no, we can auto size it. Nope, auto size seems too small. So we'll just set it to be around 30 as a good number, hit Enter o k. So with that done, let's close this down. Save all of that. Let's open up the menu manager and it's time to set everything up. So the first two variables that we need are obviously the character choice panel and the character choices names. So we'll create two serialized fields. One of them will be a game object. And it's going to be the character choice panel. And another serialized field, which is going to be an array of texts. And it's going to represent the items, character, choice, names. I know that's a long name for a variable, but we need to make sure that we understand what we're working with. And then down here, we are going to, where are we? We should be, Let's pull it down here about the discard button or know what, Let's put it under the US button so it stays close. So it's going to be a public void. And we want to open the character choice. So we're going to call this open character choice panel. And what are we going to do in here? First of all, the Character panel should be set to active. So character choice panel that set active is true. Then we'll need to loop through all the player stats. So we're going to create a for loop, or we can create a for each loop, doesn't really matter, but sometimes it does. And I'll show you maybe in this video why? So if I is less than the player stats that we have that length. So we do have a reference to all the players available. There we go. So we have the reference in here, can use the player stats immediately. And I plus, plus. So now as we're going through all of the player stats, we'll create a variable which is going to be of type player stats. We'll call it the active player. And it's going to be equal to the game manager. Door instance. The player stat at position i. Now that we have reference to the active player, we are going to access the items, character choice, name. At position i. We're going to go to the text and it's going to be equal to the active player dot player name. And finally, we need to turn on and off the button based on whether this player is active in the hierarchy or not. So what we'll do is we'll create a Boolean. So bool active layer are available and is going to be equal to the active player game object dot active and hierarchy. And I've created a separate variable for it because the next line is going to be very long. So we're going to access the first of all items, character choice name. Now what is this character choice name? It's the text on the buttons. So we need to turn on and off the buttons or set them active or non-active. So what we'll need to do is access the transform and get the parent. And then from the parent access the game objects. So now we are on the button and we'll set it to active based on whether the act of player as available. So as I've said, Maybe electron, when we assign everything in Unity, it will be clearer, but this is the text on the button. And it's, I think should be text Mesh Pro. So text Mesh pro, I think this is the first time that I don't do this mistake. So this is a text Mesh Pro. We need to access the transform first before we can access the parent. Then access the game object and set it to active based on whether the active player is available or not. So now we can save all of this. And also of course, we need a way to close this solo, create a public void, close, close character choice panel. And it's really simple. We just go to the character choice panel, dot selector, false. Save that. Now back in Unity, we need to make sure that when we go out from the menu, we close the character choice window. So let's go into the Canvas, assign everything. So if we scroll down, we have the character choice names. So open all of this up. We will lock this inspector down, shoes all of these, drag them in here. We'll drag the character choice panel and to its right position. We will save all of that. We'll close this down and we're going to turn off the character choice panel. And also we need to go back in here and when we use the item, so when we use the item, we need to open the character choice panel. So there we go. We open the character choice panel. And this will allow us to choose one of these characters on which we want to use the potions. Now this discard items should be moved. So we'll add a comment in here. This should be moving and it should be activated after we choose one of the players later on. So let's just make sure that everything is working. So I'm going to turn off the items panel and turn off. Let's just keep the items panel. Nothing bothering us. Run the game. Collect a couple of items, open up the menu, go to Items, and let's see, if we click on one of the portions we had the US. There you go. We have jimmy, Sarah, and the name which should not be available to us because we didn't turn them off in here. So let me turn back. Let me choose all of these and set them to an active. Because we are turning them on based on whether there is a player and they were already on. So let's choose, open up the menu items, use their ego only gym and Sarah or are available. Now currently, this does nothing, but at least we know that it's working and giving us a choice. So in the next video, we'll actually be choosing the character, using the item on this character and filling out everything that we need to do. So I'll see you in the next one.
65. Choosing A Character: Welcome back my fellow game developers. And in this video, we have finally been able to use the items that we've been working on for so long. So now when we go to items, we choose the manna potion. We hit the US key, we get the option to choose whether we want Jimmy or Sarah. If we click on the player right now let's take a look at the current HP. We had the US, or we've increased the manner, Let's increased demand for Sarah. And Sarah, we increase demand for Sarah. So we finally finished implementing this. So let's not waste any more time and let's get finally done with using items. Okay, so now we need to actually choose a character. How are we going to do this? Let's go into the items button. And in here we are going to add a parameter. So it's going to be an ENT character to use on. So why did I add an integer as a parameter and not an actual player's stat. Let me explain how this all going to work. We'll go into the player choice in here, and we're going to add to each also. We also need to remove all of these on the buttons. So we're going to make sure that each one of these player choice bottom has a specific number to it. We're going to, whenever we press the button, we're going to send that integer to the menu manager in here. And then using this one, this item, and then using this power, we are going to send it back to the US item on the items manager. So let's implement this if you haven't understood what I meant, I will show you as we go through. So now in the items manager use item method, we are going to go ahead and create a variable which is of five player stats. It's going to be called the selected character and it's equal to the game manager dot instance, dot get, or the players that get player's stat at the position of the character to use on. So now in here instead of player dot instance, we are going to get the selected character. And also in here the selected character. Save all of that. Next, we need to make sure we know which character to use we are going to use. So back in Menu Manager and here we are going to pass on a parameter which is going to be the selected character. And we're going to pass in here the selected character and teacher. So what happens now? Let me show you. If we go back in here, we'll select the the three players in here. We'll make sure that they are the ones that use the item. So we'll drag also, we are still in Game Mode. Oh no. Okay, so now we need to do all of this again, because all the changes that we make during game old are removed. That's so sad to see. Anyways, let's go ahead and add an on-click to all of those. Add an item and here. And then choose a theme menu manager. In the menu manager, the US item, the player choice will be 0 and the one will be one on the second choice and will be two on the last one. We'll save that makes sure that they are in the correct position. So the first player choice, which is 0, should be on the leftmost side. The one in the middle should be the one, and on the right side should be two. So we're going to save all of that. We're going to also add in here a, another method and that is to close up the character panels. So we're going to go and choose to. Where is it? Close, close, close Character panel. There we go. Save that. And finally, on the US button, we should only opened the Character panel. We don't want to actually use the item with the US button. So use button. Instead of use, we need to go to the manager and just open up the character panel will save all of that. And this should be working. And one less thing is in here when we want to open the Character panel, we need to make sure that we have an active item. So if we don't have an active item selected, we don't want to be able to open the panel. This will cause a lot of errors later on. With that saved, let's go back and let's test out finally, our code, see if it works. So we pick up the items we had and we go to the items, we go to the HP portion. Let's click on the player to make sure that we added to Genie. We use the item we choose, Jimmy and there you go. So now we've added a speed to Jimmy specifically. Now let's try to add some manner to Jimmy. Very go. So man has been added to Jimmy. Let's try to add to Sarah. Let's click on the healers MPC. Let's look. The current one is three. Let's add some manner. There you go. And Jimmy didn't get any mono. So we finally finished up with using these items. Now we still have to use the weapons and the armor. So I hope you are enjoying. I know there's not too much action in this, but we are learning very, very valuable coding information and going deeper and deeper into the complexity. So I hope you're enjoying and I'll see you in the next video.
66. Using Weapons & Armor: Welcome back, my fellow game developers. In this video, we are going to be able to use the items and armor or everything other than the items. So we'll be able to assign the gold armor. Let's choose Jimmy and assign the silver one to Sarah, assigned the golden axe to Jimmy and the silver acts to Sarah. If we go to the stats, you'll see that let me just make this bigger. You'll see that Jimmy has the golden eggs and the golden armor, and Sarah has the silver x and these silver Alma, we also see the weapons power in here. If Jimmy already has the golden axe, if we want to give them a silver x, we can exchange that. We'll see how that all works in just a bit. So let's not waste any more time and let's get started. Okay, so time to add weapons and armor. Let's first go into the player stats. Where are our player stats? Let's go up. And in here we're going to add a couple of things. So the first thing is the public String equipped weapon name. The second one is equipped armor name. Then we're going to add two more, which are public and weapon, power or dexterity. And then finally the armor defense. So this is going to be a bit different than the normal dexterity and defense. This will be the ones of the weapons specific. So we're going to save that. Next thing we need to keep in mind that we have the Stats menu. So if you remember, let's go back in here. Let's open up the menu and you can see that we had the, let's turn off the panels and let's see the stats panel. There you go. So you remember that we had the equipped weapon. This is where we are going to add everything in the values of the equipped to append the equipped armoured, the weapon power and the weapon defense. Now we've called it warp and power. Let's change this. Maybe we should keep it as it was. So when the player stats, Let's keep the weapon power. Okay, so weapon power back in our menu manager, we are also going to take all of this into consideration. So in here, we're going to add two more texts. So this is where we were using the stats. So this that we're going to add the stat equipped weapon and stat equipped armor. And we'll also add in here texts for the defense and texts 40 power of the weapon. And I'll just duplicate this. I don't want to make the line too long. So stat equip, weapon, power and stat are more defense case save that. I think that's all that we need to do in here. And we'll need to scroll down where do we update the stats? So after we set no, the Stats menu, we update the Stats menu. So this is where we should be working after we set the image, we also need to a couple of things in here. So the Stat, a quote, weapons, this is obviously wrong. So let me change that. Weapon. Stat equipped to happen. Enter dot txt is equal to the player selected dot equipped weapon name. Duplicate that. Stat are more defense dot selected weapon equipped armor name. Save that. Now we need to more those that will represent the power and the armor defense. So it's going to be the stat weapon power. The text equals the player selected player pledge selected. That weapon power. Duplicate that. Stat, are more what we call it the stat armor defense. Okay? So the stat armor defense dot txt player, the are more defense. There we go. Save that. What's the problem in here? And it's an integer. Oh, how nice to string, dot two string. So that's it. Remember a couple of challenges ago, this was a hint. That's why it's a hint because sometimes we might forget what's the problem. Now time to add the weapons from the items. But first we need to consider what happens when we actually equipped weapon. When we equipped weapon, we want to let go of the weapon that we already are holding and put it back into the inventory. So we need to keep track of the items the player has, the player stats. So any player stats, we're going to create two more variables in here, which are going to be of type item manager. And it's going to be the equipped. I always get the word equipped wrong. So I hope it's not completely wrong. Equipped weapon and the equipped on soap equipped and the equipped are. Okay, so we'll save that. And now it's time for a challenge. And your challenge is to equipped weapon and all. So create two methods to equipped weapons and armor. Each should take an argument of the weapons slash armor to equipped. Said the equipped weapon slash armor set the name of the weapon and the dexterity slash the difference. So all of that should be done in the player stats. If I'm not mistaken, it's, you're also a challenge for you. So pause the video right now and go do the challenge. So back in our player stats, we add XP, we add HP, we add mono. And we can also equipped weapons. So where should we be doing it? I think under demand, let's do it in here. So it's going to be a public void equip weapon. And it's going to take an argument of Item Manager and it's going to be the weapon to equip. And in here we're going to set the equipped weapon. Why did I choose such hard names of four our variable. So the equipped weapon will be equal to the weapon to equipped. The equipped weapon name will be equal to the equipped to happen. Let me just copy this. Equipped weapon dot name and the equipped to weapon power. Let's try power. Okay, so weapon power is the equipped to open dot weapon dexterity. Save that, will duplicate this because it's pretty much the same. So instead of equipped to append is going to be the equip Armen weapon to equip. Armor to equip. And the equipped armor is equal to the arm to equip. And the equipped. And let's try it. The steroid hormone. Maybe this will be easier. So equipped armor name, our Marie de France. Copy this, paste it in here, and paste it in here. Item name and are more defense save that. So all of this should be correct. Will check later on if we have some kind of error. Now back in the items manager, we need to check for the weapons and armor cues. So in here, we check for the item. If it's not an item, then we're going to create an else. If the item type is equal to the item type dot one and if the selected character dot equipped item, whereas it so the equipped weapon, I mean, is different than empty. So that means we have some kind of weapon in here, equipped to happen name. So equipped weapon name because we were comparing an item manager to a blank string. We are going to go ahead into the inventory. We are going to access the instance. And we're going to add an item, which is going to be this item. It's the one that we are currently, and we're going to add the selected character dot the equipped to happen. So equipped weapon. So what this does is it checks. First of all, are we trying to add and a weapon? Yes, we are. Does the character already have opened on him? Yes, he does. That means we need to add that item to the inventory and instead, we are going to replace it with the selected character dot equipped weapon. And we're going to set it to this or no movement to add. This should be the method. So equipped. We need to equip weapon and we need to pass it a parameter and it's going to be this, so it's the current item that we are working on. And finally, we need to add an another else-if. And we're going to check if the item type is equal to item type dot ARMA. If it is, then we're going to check, let's just copy this because it's pretty much the same. So we're going to check if the equipped, Let's try this armor equipped Armen name. If it is, then we'll add an item, the selected character equipped armor. And then we're going to equip and Narmer and it's also going to be this. So let's save all of those. Let's go back in our game. Let's see if that works. And you know, we also might need to update the stats at some point, but we'll worry about that later on. So let's run our game. Let's turn this off. Let's look at the player and you'll see that we have no weapons equipped, no armor equipped. So I'm going to go get some armor. We're going to open up the menu, go to the item, select the gold armor we're going to use. We're going to set it on Jimmy. And yep, there we go. So we have the equipped armor on the jimmy character. If we go to the stats and there is a problem because we haven't set the instance of value. Let's worry about that. Later. We'll add a golden axe to Jimmy. Okay, So there you go. The Golden x. If we tried to add the silver acts to Jimmy, the Golden Axe appears and our items list. Excellent. And let's add that Sarah. Select the golden acts at that Sarah, and you can see that we already have a slight problem and duplicating items. So to add that, Sarah, now Sarah, the healers should have a silver armor and a golden axe. So with that done, let's go back into, let's see our stats. We need to see the values. Go to Canvas, lock that down, scroll down, and the item character, where are we at? Okay, so the stat equipped weapon, so stat equipped to happen, Let's see. The weapon power should go and hear. The armor defense should go in here. The equipped weapon should go in here, and the equipped honor should go in here. We'll save all of that, will run the code again. We'll turn off the menu, speak up a couple of weapons, and there you go. Coppa items. Use it on Jimmy. Use the god 14, Sarah, use the gold armor for Jimmy, use this silver armor for Sarah. Let's go to the stats and let's look in here. What do we have so equipped to happen is the silver acts to equip armor is nothing. Then for some reason the equipped armor isn't showing up correctly, so we'll see how to deal with that in just a bit. Let's see what the problem is. 0, okay, so in here we can see that we use the armor defense, not the armor. What was it called? Let me go back up to where it was these that equip armor. So there you go, the stat equipped armor, save that now everything should be working fine. Let's run our game. Let's pick up the items. Let's give the silver armor to Jimmy. Go back to stats, choose jimmy, There you go. You can see that the equipped armor is the silver and it also has an armor defense of six. So we finally finished creating our inventory. We finally finished checking our items in the inventory. We've done a lot of things. We've used the items. We, this was a big, huge section, so I hope you enjoy it and I'll see you in the next video.
67. Section 9: Shop Tiles: Welcome back, my fellow game developers. In this video, we are just going to be laying out the groundwork for our shop. So first of all, make sure to go and apply everything to your canvas prefab, because we've already added a lot. We haven't applied to the Prefabs or Canvas override. Make sure that you apply everything you have to create the game manager Prefabs or simply drag the game manager. And here, make sure to also apply the changes on the player. And when you're done with that, let's go ahead and create a new scene. We'll call this the Save that. So this new scene, we can keep the main camera. We don't need to have a follow cam. We can just have a static shop where we don't move the camera is just one shot and you move around and that shop. Or if you want to do it differently than go ahead. So in here we are going to, first of all go to the prefabs and we're going to add the grid. So we'll add the grid, will right-click and go to the prefab unpack completely. So this is a very vital point. Now it's time to use the tiles. I've provided you with a set of files, so we'll go into the resources. There you go, It's indoor. Let me just add this file so we'll right-click or go back. We'll jag and the indoor. And there you go. There we have the indoor. Now we're creating a new tile palette is going to be called the indoor Create. And we'll create it inside of the indoor tile. There we go. So now we have a new tile palette. Now we need to set the sprite mode to multiple. We need to apply the changes. We need to go to the Sprite Editor. And in here, I found that the perfect size is 16. By 16 was one offset of the top. We will slice all of that. There you go. So this will give a very nice slice, except for the edge down here. So you'll notice that there is no slice on the spot because we've offset it by one. You can see it right here. And because we've offset it by one, you can see there is no slice down here. We'll deal with that later on. But if we slice everything, there will be a big problem in the tile palette window. It's not going to allow us to do everything smoothly. And if you have your own sprites, then you'll need to find your own way of slicing it. You can even do it manually. So we're going to apply all of that. We're going to drag the pilots. And here we're going to make sure that we select the Endo file for the tile assets. We'll select that. And there you go. We can start by deleting everything. So we'll create a object or select multiple files. Delete 0. Just go out of editing, delete. And we're going to go ahead and remove everything and our world from objects to the background. To the background objects. So there you go. Now we can start fresh. So for example, we'll have this as the background. And there we go and just draw this up. And you can see that we need to make it bigger. Let's try to make it 32. Apply. 16. I believe 16 will be the good number. There you go. And now we can start adding carpets and so on. And for the bottom edges, we're going to again go to the Sprite Editor. We are going to create a box in here that's going to be the size. So exactly the same width as the one above, but a bit smaller height, so it's 16 by 15. So we'll create multiple files again in here. And this is going to be 16 by 15, 16, 15. And we'll set it in the correct position. This one too? Nope. This one too. 16 by 15. And I believe we'll need another one. This one should be 16. There we go. Unfortunately, I haven't found a more faster way to do this. So I'm doing it all manually. I'm sure there's a more smoother way and easier way to just copy and paste. But there we go. So we've sliced those up, we're going to apply. But make sure that you don't simply drag this into inhere. So we need to get the specific sprites which are on the bottom. We need to differentiate between these sprites. So there we go. We'll select the last few. So it's these 123. There you go, you can see them right here. We'll drag them in here. Yes. It's in the indoor file and as you can see, they are not set up correctly. So what we can do is make this bigger a bit. First we'll go into the Edit mode. Then we will select these two. For example, click on the move, will set it in here. Again, select Move. And as I'm, there we go As, um, and I'm saying as I am because you can see right here that the US is a hotkey and VM as a hotkey also. So as I'm, and there we go, we've set up our tiles now we can draw everything. And it's asking us where do we want to save the scene? We'll go to the scenes, will create a sharpened here. And there you go, Save all of that. Now, it's time for a bit of a challenge. And your challenge will be to create your own shop. So create and set up your own shop using the tiles and download your own indoor slash shop tiles and create a shop if you don't want to use the ones I've provided you with, you can go to Open game art or any other website and find everything that you need in there. So before I go, I'm going to leave. You will need to also add the player. So we'll need to find the prefabs player and we'll need to make sure of course that we change up, for example, the background. You can see that it's very big query to make the polygons smaller and make sure to add the edges, for example, to be a wall that are solid and the player can't leave from there. So I'll leave you to it to create your own shop. And in the next video, I'll show you what I've created and we'll continue on. So I'll see you then.
68. Setting Up Shop: Welcome back my fellow game developers into this very long video. I know it's around 20 minutes maybe, but it's all building UI. So as you know, this is personal. I'll just show you the layout and then you can create your own. So what we did in here, we created a cell panel by panel and exit Shop button, a currency to use value of the item and so on and so forth. So let's not waste any more time and let's get started with our shop menu. O k. Let's get started. I feel this will be one of our longer videos. So first of all, we need to commit our changes. We need to make sure that we ignore everything beneath sea assets style, styles and hit OK. Now stage of and now we're going to commit our changes. Created a shop, commit them. Back in our game. There you go. This is my little shop. And before we forget, make sure to add a level manager and sat deep background tiles that. So now when we run the game, There you go. So let's see. There we go. We can't move through the walls. We can't move through the chairs and objects that we've created. So it's not a very fancy, it's very basic, so nothing too fancy in here. I may place to exit, so, or a place to enter, but the player can move through that. So now it's time to start creating the shop manual. For that. We're going to add the Canvas into the hierarchy. There we go. And in here we are going to do a couple of stuff. So we're open up the Canvas, we can get rid of the Tile Palette, close the tab. We're going to duplicate the menu and we'll call this D sharp menu. So shop menu. And in here Let's just turn off the menu, keep the only the shop menu open. And we're going to do a couple of changes in here. So the first thing we're going to do is the buttons. So the buttons are going to change. So instead of items in here, we're going to have the buy button. Instead of the stats will have the cell button. And the final one which is going to be the save, is going to be the Exit button. Not as sexy button, the Exit button. And we're going to delete the last two buttons which are close and quit. We're going to go to the buy. We're going to let me just minimize. And of course all of these will be changed on the cell, the exit, and so on. So the cell has these onclick entities or objects. And we're going to enter the text. The text on the button is going to be by on the cell is going to be cell. On the exit is going to be exit shop. Hit Enter. And we're going to make this button a bit bigger. Also, we're working on the grid. Let me make the grid actually lay out a bit bigger. So we'll increase the size of the cells because we'll also add the money in here so we don't want it to fit or everything and we'll increase it in the y also. And let's see, move it up on the top and the cell size, let's increase it even more for the exit shop. So the exit shop will make this a bit smaller, or is it too small right now, we'll increase the size of the text box. And as I've said, whenever we are creating UI are recommended should do your own creations. Because all of this is very subjective and you can change whatever you want. And I'll just move it down. So there you go. Exit shop. Nope. Exit shops, sell and buy. Okay, So now that we have the main buttons, it's time to set up everything else. So the character and fall is going to go, the stats panels going to go, we'll only need the item panel and here, and we'll also do a couple of changes. So let me minimize this because we're working mostly appear. So what are we going to do in here? Well, we are going to have two sets of panels. So we're going to have the cell panel or the by panel does matter by panel. And then we'll have the cell panel. So there you go, sell pan. So what do we have in the bike panel? We're going to remove the discard button, the US button. We're going to rename it to the buy. And we're going to change the text also in here to buy will keep the item's description and the items display panels. So everything in here is going to be the same. The choice panel doesn't need to be in here. And we probably should have done that and then duplicate it. But no worries about that. We're going to add also in here a text Mesh Pro, or simply a text. And it's going to be the value of the product. So value. And in here we're just going to write value and we'll just have one of them will change. As always, we need to set it as the medieval. We need to make it completely black. And we're going to drag it down next to the buy button. So yep, there we go, That's about it. And this will be the value of the item that we choose to buy while on the cell panel. Let me just and were we working on the cell or the Bible should have turned that off. Yet we were working on the cell. So instead of the Buy button, this is going to be the cell. And the words on also are going to be cell. Okay, So this was the cell panel. Everything is set up in here and the buttons up here, the big BY and the big cell will take us to, from panel to panel. This in here will allow us to sell an item. This will be what we already have in the inventory and then we can sell it. While in the bypass diode will have some kind of shopkeeper that will open up the panel, will remove the C, what we have used. This button needs to go, this will be the bye. And also in here, the shopkeeper, we'll have a couple of items for us to buy. So we'll need the value that we have in here. So duplicate the value. Put it up here. There you go. So now we have the value of the item, and I'm sure we'll need to make this a bit bigger. So let me choose the right tools and increase the size as much as we can. There we go. And on the value down here will also make the same adjustments. So there we go. So now we have the cell panel by panel. I think that's all that we need, o and we also need a label up here on the shop menu. So we are going to right-click and new UI, add the text Mesh or know what we could have simply used one of these value. And let's just name and value. And we're going to, we're, we're, we were going to duplicate the value in here. And we'll move it up in the shop menu. And we'll move it up here. So there we go. And this will be V of currency that we are going to use. So you can choose any currency that you want. I'm going to use Bitcoins. And that's because currently El Salvador just got a bit going legalized. So it's a legal tender. We can use Bitcoins if you're unfamiliar with bitcoins are recommended to read about a debit, say great technology, especially for game developers moving on and any kind of programmers honestly. And this will be the amount of VDC. Vdc means but are less amount of Bitcoin. Okay, great, so now we have everything set up. Now, it's time to start keeping track of our gold and so on and so forth. And also, of course, creating a shop manager. First of all, what we need to do is we'll need to add a game manager in here. There you go. We have everything set up. We need to keep track of our bitcoins and how are we going to do that? And we shouldn't make it a child of the canvas will put it up here. How are we going to do that? Well, we could have tracked the amount of gold that we have on the player. That's a good idea. But as we have a game manager with the inventory and so on, I think the best place to do that is in the game manager script. So let's open up the game manager. And in here we're going to create a, another public and ropes and game. I mean, current Bitcoins. And we'll just keep track of all of that. Now. Obviously, we shouldn't make it public because we don't want any other script to have access to it. But for now we'll just keep it like that as we have an instance. And I don't feel it's necessary to create a another function just to get the current Bitcoins. So we'll save that, okay with that setup, the next thing we need to do is to go and create a shop manager. So we'll go into the scripts, wait for that to compile any day now, we'll go into the scripts, will create a new folder in here that we'll call the shop. And inside the shop we are going to create a C-sharp script that's going to be called the shop manager. Hit Enter, wait for that to compile. We're going to add it to the canvas. So to the canvas, as you can see now, the Canvas will have the menu manager, the dialogue controller, and a shop manager. Okay, great. Let's open up the shop manager and Visual Studio. And what should we be doing in here? First of all, we'll need to create an instance of this class. So we'll create a public static shot manager instance. We're going to set the instance to this. And what do we need to do in here? First of all, we need a reference to the shop panel, the panel and the cell panel. So we're going to create public game object, and we're going to have the shop menu. So this is the entire shop many that we have will have access also to the buy and the sell panel. And we'll need to set everything up and unity. But before we do that, we'll need to create a method that will open the shop menu. So we'll go into create a public void, open shop menu. And in here we'll just get the shop menu and we'll set the active to true. Okay, great, So you already know what this does. Now the next obvious step is we want to stop our player whenever he opens the shops or when we start talking to the shopkeeper and we have the shop opened up, we want our player to just stop. It doesn't need to start moving while talking to the shopkeepers. So it's going to be part of your challenge. Your challenge is to stop player from moving. Yeah, again, so whenever we open the shop, the player should stop moving. I'll give you a couple of hints. First, create a variable and Game Manager and update make the variable to one of the conditions and change the variable when we open the shop menu. So with that said, with all those, hence, we've already done this before. Pause the video right now, and go do the challenge. Okay, welcome back. So where were we? First of all, we'll need to go into the game manager. And we'll need to add another volume in here, which is going to be the shop opened. Opened just to stay consistent again, many open dialog box opened, shop many opened. And where are the conditions? So we're going to add a condition in here if the shop is opened. Now what else do we need to do? Create variables, update, change the variable when we open the shop. So we'll go back into the shop manager. And here when we said the shop active to true will access, the game manager will access the instance, will access the shop opened and we'll set it to true. Oh, okay, Great. So that done. What else should we be doing? Well, obviously, we need to be able to close the shop, so we'll create a public void close shop menu. And I know I'm not testing everything out, but we've already covered most of this, so I'm trying to go through it a little bit faster. So we're going to use these two lines. And we're going to set the set active to false and the game manager Door instance or shop open to false. Now we need to have the ability to switch between the panels. So we need to switch between the cell antibody panel will require two more methods. And we could have done all of that on the onclick, but let's try a different way and try to use just the methods. What I meant is that we could have turned on and off the game objects using the onclick on the buttons. But now we're create a method or methods to do all of that. So enough talking, let's apply all of that. So we'll open by panel. And in the bike panel will access the by panel set active to true. And we'll need to set the cell panel to set active to false. Will duplicate this because it's basically the same. And we're going to open cell panel. So by paneled false, cell panel, true. Okay, Great. And finally what we need to do is when we open the shop. So when we open the shop menu, we also need to make sure to set the Bitcoin labeled correctly. Do we have a reference? Nope, we don't need to add the impro, So using the m per row so we could access the Obviously the text Mesh Pro, we're going to create a variable in here which is going to be a serialized field. And it's going to get access to our Bitcoins. So we're going to call it the text Mesh pro GUI. And it's going to be the current Bitcoin text. Save that. And now where is it? When we open the shop menu, we want to set the current Bitcoin texts. So it's going to be the current Bitcoin text. The text is equal to BTC two points. And in here we're going to concatenate a integer game manager. Dot instance dot will access the Bitcoin's current, but coins. I think that's enough, or do we need to add a two-string? Nope, There we go. Save that. Now let's open up our game and see if any of that actually works. So we have a couple of things to do. So open up the Canvas, open up shop, shop drop menu, and let's add the shop menu. Let's lock this in. We add the bypass, the cell panel, the current Bitcoin text. Save that. Now we'll need to open the buttons and make sure that we set everything up correctly. What's this? Was this like that. Okay, so fix that. Okay, so now what we need to do is we'll need to add some functionalities to our buttons. So first we're working on the big button that opens up the panel. So we'll open it up. We're going to add the canvas as the object. We are going to access the shop manager. And what does this do? It opens up V by panel, will go to the next big cell button. We're going to also add the functionality at the Canvas. Go to shop manager. And we're going to open cell menu. So open cell panel and the exit button. So this will exit the shop. We're going to, oops, close up shop. So Function Manager, close shop menu. So there we go. Let's save that. What else do we need to do? Let's see, do we have any other open source, open close. Okay, and also we need to do one more thing. And that is whenever we actually open our shop, we need to set it only by menu. So we're going to access the menu or the bike panel dot set active, true. So this will, as soon as we open the shop, we are going to access the bike panel. Save that back in here. Let's wait for this to compile. Let's run our game and see if any of that worked. So currently, uh, let me go to the game manager and give us able of Bitcoins. Let's give ourselves 32. That's really good number, save that, and let's try it. Go to the cell. Oh, I'm working down here. So cell. None of this is working because, and you might encounter this problem to, why aren't our buttons working? Because we don't have an event system. What does an event system? Well, let me show you the other script and the other scene. I mean, so we'll go to town to double-click. You'll notice in here that we have an event system and this is what allows us to actually interact with the buttons. This is what keeps track of what we click on our game menu. And because in this canvas and the event system are separated when we added a canvas by using the prefab, we didn't get an event system. So what we'll do is we'll drag in the event system the canvas. We certainly don't need to do that because if we apply the canvas in here, everything that we did previously and the other in the shop menu is going to be destroyed. So back in here with our shop menu, we're going to right-click and go to your eye and add an event system. We'll save that now if we run our game, I'm pretty sure that everything should be working. So there you go. Sell, we sell, buy, buy, exit shop, we exit chop. And unfortunately we don't have yet a way to update Debussy, but we will get there. So I hope you enjoyed this very, very long video and I'll see you in the next one.
69. Setting Up Shop Keeper: Welcome back, my fellow game developers. In this video, we are going to be activating the shop and deactivating it based on whether we are close enough to the shopkeeper. So as you can see, we have the small Trigger box. If we are inside of it, we can open up the shop. We can go to the cell to the why. Of course, we cannot move our player while we have this open, you can see that our BDC are 32. We exit the shop. We can move around again. If we try to open it anywhere else, we can't. So let's not waste any more time. And let's go ahead and set up a shopkeeper. O k. So time to create a shop. I've already added a shopkeeper. So I used one of these sprites that I provided you with. I used one of the downfall. I've had him in here and I've set him up, up here. I've also made sure to slice up the sprite and add the image in here. Okay, So now with our shopkeeper, sprite finished, it's time to go ahead and create a new script in the shop. And it's going to be a C-sharp script called the shopkeeper. Hit Enter, wait for it to compile. There we go. So now if we go on the shopkeeper, let's add the scripting here. And we're going to add also a couple of things too. So first of all, we'll add a collider to him. So a box collider 2D just around them. Let's see how big that is. Yep, there we go, That's enough. And we'll add another box collider and this will be a trigger. So the first one is just to be unable to walk through him. The second one will be V area where we can actually access the shop. So we'll just create one. And here we were moving the wrong box collider. So let's try this one more time. And we'll make this one smaller, this one a bit bigger. So there you go. Well, make it a bit big so we have more space to move in. And there we go, make sure that this is a trigger. The second one, the lighter. The big box collider. Yes. Okay. Now let's go ahead and open up the shop script or shopkeepers script. And in here, first of all, we need to create a Boolean that will check if we can actually open the shop. So it's a private bool can open shop. So it's not a serialized field. We don't need to see it, but what we do want to see is a array of items. So we'll create a serialized field. It's going to be a list. And then I say array, I meant list, and it's going to be a list of items. So the items manager, this is the type and we're going to call it the items for sale. And the only problem in here with creating lists is that it won't show up in the inspector will save this. We'll go back into a unity. And there we go. You can see that on the shopkeeper we have the items for say, Okay, great. Now what we need to do is we need to be able to open the shop menu and the clothes. And your challenge is to trigger enter and exit. So create a on sugar enter and exit in the shopkeeper. Check for the player in them and said the can open shop boolean to true or false based on, you should know based on what. So pause the video right now and go create the trigger, enter and exit. Okay, welcome back. So in here we're going to create an own Trigger Enter. And we're going to check FV collision. The DAG is equal to player. So this is something different than the compare tag. We're actually accessing the tag on the collision and then comparing it to the player. And if it is the player, then can open shop is equal to true. Will duplicate or Novak, it's not duplicated on trigger exit to the and we'll just copy this. There we go. Paste it in here. Can open shop is false. There we go. So now if the player and Thursday collision, we set it to true, that means we can open the shop. If we are outside of it, then we cannot open the shop. Now, we need to get a input from a certain button to be able to open the shop. So an update we're going to check if we can open the shop and input dot get buttoned down. The fire one I think it was called. So. Even though it's a string reference, we'll just name it firewalls. If we do have an error or something doesn't open, then we're going to check back. And we need to also make sure that the player, so the player script with an instance and the deactivate movement is set to false. So we need to make sure that the player can walk around and you'll see later on what I mean by that. And finally, we need to make sure that the shop isn't already open. So FV, shop manager, dot instance, dot active, dot gameObject dot is active and hierarchy. Active and hierarchy. So we can add a entering here. There we go. Just do not have this long line. So we need to first of all make sure that we can open the shop. We need to make sure that we hit the input key. We need to make sure that the player is able to move. So we did it. We haven't the activated the movement yet. And finally, we need to make sure the shop menu hasn't been opened yet. Okay, Great. And in here instead of game object, we need to be Shot menu because the shop manager preferences, whenever we write shop manager instance dot gameObject, we are referencing the game object which has the shop manager, which is the canvas we need to access the shop menu. Okay, So with that Don, what are we going to do in here? Well, of course we are going to open up the shop. So shop manager, dot instance, dot, open shop men. Save that. And before we go and test this out, there's one more thing that we need to do, and that is set a list of items in the shop menu. So if we go to the shop manager, will need to create in here a list of five items manager. And it's going to be the items for sale also. So in the shopkeeper, we opened the shop and then we are before we even open the shop, we can access the shop manager, shop manager dot instance dot items for sale. And it's going to be equal to the items for sale that we set in here. So this is the object which is then shop manager, while this one is the one we are using for the shopkeeper, Let's go too confusing for you. I recommend you change the name. Let's go ahead and change the shopkeepers item for sale. Okay. So there we go. Shop keepers items for sale. Apply that. So now the items for sale in the shop or the shopkeepers items for sale. So we're going to save all of that. We are going to go back into Unity. We are going to run our game and we're going to go next to the shopkeeper and had the fire key. And there we go, we have to buy the cell and the exit shop, and we can exit the shop. If we open the shop, Can we move around? Nope, we can't. When we exit the shop, there we go. We can move around. So excellent. Everything seems to be working. In the next video will be actually showing the items that we want to buy and sell. So with that done, I'll see you in the next video.
70. Items To Buy & Sell: Welcome back, my fellow game developers. In this video, we are going to allow the ability to buy or to visualize the items that we want to buy and sell. So as you saw right now, I picked up a couple of items. I went to the shopkeeper, I click on the Menu and voila, I can see immediately that I have the acts and everything that is available on the shopkeeper to buy and we've added all of these manually from the shopkeeper right here. If I unclick it, you can see that the shopkeepers item for sale. There you go, the silver acts, the golden armor, and all of that. And now if I go to the cell panel, there you go. These are the items that I've picked up and that I can. Now currently they don't do anything, but for now, our main goal is to visualize all of them. So let's not waste any more time. And let's get started. Oh, so time to visualize the items that we want to buy and the items that we want to sell. So this is going to be pretty similar to the way we handled the items in the items menu. So we're going to go into our code. The first thing we need are references to the item slot container, which is going to be the button and the icon slot container parent. So we'll go into the menu manager. And if we scroll up here, we can simply copy the item slot container and one for the parents. So we'll copy that, we'll paste it in here. We'll save this. And when we open the bimanual panel, we want to go ahead and update all of that. So how do we update it? Well, it's also pretty similar to the one that we are using in here. So in the menu manager, where we update the items in the inventory are going to copy all this code. And we're going to go ahead and paste it in here. But instead of using the inventory, so when we're looking through all of the items in the menu manager, we use to look through the inventory and the shop manager, we are going to go ahead and look through the items for say, Save that. And one more thing that we need to change is the amount. So we'll assume that the shopkeeper always has an infinite amount of access. We won't be going out of our way and implementing some kinds of limited amount of weaponry. We'll just keep it as infinite for now, just for the sake of simplicity. So we'll need to make sure that this is an empty, we'll save that. And if we don't create this kind of if condition if statement, you'll notice, you can try it, but because the default state of this image is with 999 at the bottom, we need to make sure that we set it back to an empty string. So now Let's go into the shopkeeper and let's add a couple of items in here. So we'll add a golden axe, will add a golden armor. We'll add two more. We'll add a Silver up here and a silver armor down here, and a golden acts at the end. We'll save that. We'll run our code. And let's see if that works. If we go up to the shopkeeper, we go to the bimanual and there you go. You can see that we have updated our buy items and if we click on one of them, nothing happens. If we try to buy, nothing happens and the cell menu is still not working. So let's go ahead and fix this cell panel. Now in the cell panel, we can actually use the scope from the menu manager exactly as it is y, because we are using the items in the inventory that we have an order to sell them to the shopkeeper. But there is one little problem. If we copy this code and put it in the shop manager on the bike panel, it's going to work perfectly fine. You can even test it yourself. There is no problem with. But as a professional programmer, and as we are moving through this course, it's better to start using more advanced techniques and habits. And one of those habits is to never have duplicate code. So we want a way where we can create some kind of method that can do both functions using the item container parent. I mean the items for sale whenever we are selling on the cell panel and at the same time work for the bike panel. So let's go ahead and do something like that. The way we'll do this is we'll create a method that has two arguments. And one of those arguments is going to be the inventory that we are going to be looking through. So we're going to scroll down and under here we're going to create a private void. And it's going to be called update items and shop. And it's going to take two arguments. It's going to take the item slot container parent because we have, as I've said, or maybe I haven't, we have two kinds of item container parents, one ND by panel and one in the cell panels. So you can see right here the items display panel for the cell panel and the items display banner for the bi panel. So this is the first part of the argument that we want to send. So it's transform the item slot container parent. And the second one is the list of items that we are going to look through. So it's going to be of type list item manager. And we are going to call it the items to look through. So items to look through. And now we are going to cut this code from the opened by panel. And we're going to paste it in here. And instead of the items for sale, we are going to look through the items to look through. And the item slot container is the same as n here. So I've already pre-programmed this. And when we open the Bible menu, we are going to go ahead and call the update items and shop. And the item slot container parent. We're going to call this the item slot container, or the items thought by container or container. Let's put it up here. So the items thought by container and the item slot cell container. So we'll save that. So when we are updating the item shop from the bi, who are going to send the Item slot by container parent. And the list that we are looking through are the items for sale. We'll save that. But when we open the cell panel, we are going to update the items and shop. And actually I'm going to move this up. So hold down Alt. Move this up. Yep, there we go. Spattering here. And we're going to use the cell itemset, slot container parent. And the list that we are going to look through is the inventory dot instance, dot, get items list. So there we go. Now, all of this should be working perfectly fine. So let's go into Unity. Let's go ahead and add a couple of items in here. So we'll add a golden acts that we can pick up a golden armor in here just so we can see it in our items when we want to sell. So we are going to run again and you forgot something. We need to go into the Canvas, scroll down. Let's close this. We're going to add the item slot container, the buy and the cell. So the cell, this one. Let's lock it down. The items displayed banner from the cell will go to the cell and the items display panel on the buyer will go into the bye, save that, run the game, and let's test this out. Let's pick up the items. Thank you. Let's go into the shopkeeper. Hello there. By Yep, There we go. These are the items that are available for us to buy. And if we click on cell, there you go. These are the three items that we have picked up. Now, this still doesn't do anything, but at least it's working completely fine and 100% accurately. O K, Great. So with that complete, in the next video, we are actually going to start selling and buying our items. I'll see you in the next one.
71. Buying Items: Welcome back, my fellow game developers. In this video, let me just show you what happens. We are going to collect a couple of items. We are going to access the shopkeeper. When we click on buy, we see that when we select one of the items, we get the description, the name, and the value of that item. If we click on the, for example, let's say the golden armor, its value is 35. If we go to sell it, we can see that we have a golden orb, but its value is 26 because that's always a bit cheaper. So, well That said was that shown? That's not waste any more time. And let's get started. Oh, okay. Now time to add some functionalities to the buttons that we are instantiating and the buy and the sell panel. But there's a slight problem. We cannot modify the actual button. Why? Because we are using the same prefab on the cell and buy panels as we are using on the items panel. So this is going to be a bit of a problem. What we will do is we'll go into the items button. And in here we are going to modify. So we're going to check if we are working in the menu, if we are working in the shop. If for working in the shop are going to check for working in the cell or in the BI. So let's go ahead and start implementing that. First of all, when we press the button, we are going to check if the menu manager, dot instance, dot, active and hierarchy. I mean the.menu, we need to access the menu before we do that. So the do we have access to the menu if you go to the menu manager up here, so the Gaining, so the menu isn't accessible. So we're going to change this to a public so we can access it. So in here.me. So if we're working in the menu, because remember we have a shop menu and a regular menu. If we are working in the menu dot, active and hierarchy, then we are going to open up the brackets and we're going to use the code that we were using. And before we continue with these two lines of code and they are not that good. So you don't want to be changing anything in the menu manager that you can change in here, it's better to send this information, the items on button name and the items on button description to the Menu Manager and change that a much more better way. But I'll keep this and I'll add a comment appear that this is bad coding. It's better to send the name and this corruption to the Menu Manager script. And that way we can also make sure that these two can be private or serialized field. Okay, with that done, next thing we're going to do is you're going to check if the shop menu is open. So if the shop manager dot instance, dot shop menu, dot active and hierarchy, then we're going to check another time if the bimanual is open. So if let's copy this because it's pretty much the same. We'll paste it in here. And we're going to check if the VI panel is active. I was calling get menu. It doesn't matter, it's pretty much the same. You know what I mean? And what are we going to do in here? We are going to first of all create the else statement. Else can create an else if, if you want, just to make sure. So else if copy that, paste that in here, if the cell panel is active in the hierarchy, we're going to do something else. But what are we going to actually do? Well, whenever we click the button, what do we want to happen? We want first of all, the name of the item to be filled. We want the description of the item to be filled. We want to get the value of the item. That's pretty much it. I think if we'll need anything else, will think of it. We'll do it on the fly. So just like professional game developers, but we don't want all of this to be handled inside of the item button. Instead, it's much better to width and the shop manager. So in here, we are updating, we are opening, closing. We're going to create two more methods in here. One will be a public void selected by item. And it's going to take in a variable which is going to be the IT manager or of type item manager and the item to buy. So whenever we are calling the selected item from the Items button, we are going to provide it with the item on the bottom. I hope that's clear. Now, the other method that we want to use is we'll copy this, paste it in here, and it's the selected. Cell item that we are going to use and before we continue on because we are using the texts and the description and the value to set everything, we actually need a reference to them. So up in the shop manager, Let's get a couple of references. So first of all, we'll create a serialized field. It's going to be of type item manager and it's the selected item. So this is something that we've done for another serialized field which will contain the texts. So text, Mesh, probe, GUI, it's going to be the by item, name, The by item. Because corruption and the by item value. And we're going to duplicate this line and instead of y, we're going to sell, sell, and sell. And these are going to be different and you'll see why in just a bit. So with that save now that we have reference to all of the different texts and D-sharp menu. Let's scroll down and see what we can do in here. First off, we're going to access the selected item and it's going to be the item to buy. Then we are going to access the by item name dot text. And it's equal to the selected item to by that name, dot item name. So name and item name are very different. The name is the actual name that we set in here. So for example, this is the shopkeeper, but the item name is something that we add in here and the items manager, so item name, Golden Axe. Then we need to fill in the description. So by item description, by item description dot text selected item, that item description. We're going to save that. And finally the value. And that's going to be the cell item C. Let's type and value the item value. The text is equal to. And in here, let me just check if we need to concatenate anything. So let me turn off the shop. The value that c, This was, okay, so it's one single text. So we are going to concatenate value two points plus T selected item case. So select, it's not taking selected item, Thought, value and coins. So we've already created this variable when we were creating the items in here in the items manager. So the item's value and coin. Okay, great. What that non, Let's save that. Now let's go and try to call it from the Items button. So if it is in the BI panel in here, we are going to tell it that we want to access the shop manager dot instance dot selected by item. And we can see in here that we need the item to buy. So it's the item on the bottom, that's the item that we are looking to buy. And in here we are going to call the other method, which is the item, cell, selected cell item. And now it's time for a small challenge. And your challenge is to finish these cell menu, so called the selected cell item from Items button. I've already done that for you. Complete the method in shop manager. It's the same as in the by almost check to see if everything is working using the debug dot loc. And why do I say that it's almost the same? Well, because, you know, whenever we are working in a game or any RPG game, almost any game. I believe if you want to sell an item, its value is less than whenever you want to actually buy it. So when you want to sell something, for example, let's say you want to buy the golden plate armor. Its value is 100. But when you sell it, its value is maybe 75. So it's not the same when you want to sell something versus when you want to buy sold you'll need to reduce the value when you want to sell an item. With that said, pause the video right now and go do the challenge. Okay, welcome back. How did you get on with that? So it's pretty much the same exact thing. We are going to copy this, paste it in here, and instead of item to buy, this is going to be the item to sell. We'll paste it in here so it's the item to sell and the value, instead of being just devaluing coins, we are going to multiply it by, let's say 0.75 eth. And will this work? Will this give us an error? I think it might. So let's just keep it as it is. Maybe it won't. So we'll save all of that. We are going to go into Unity. We are going to go into the Canvas and we're going to set all of these. So the by item name. So make sure to add the value, the description value, the item values. So it's in here, the cell. So let's close down the buyer panel that's opened up in here. So the item name, the item description, and the 0 plus it's the value down here. We'll save all of that. We are going to run the code and hopefully we don't have any mistakes or going to run our game. And let's just exit the sharp. Let's pick up a few items. Let's go to the shopkeeper, go to buy. If we click on the silver, there you go. So you can see we have a silver armor. Fema, make this bigger silver armor. This will defend from monsters and its value is 15. If we go to the cell and we select, or let's select the gold armor. Its value is 35. If we go to the to sell this armor, we click on it and nothing seems to work. Why is that? And that's because in the shop and the selected oh, okay. So we didn't change the cell, cell item name, cell item description, sell Item value. Now this should be working. So that's why you never copy and paste and just do it. You need to always make sure that you know what you're copying and pasting. So now we go to the shopkeeper who want to buy the golden armor is 35, we go to solid. Its value is 26.25. Okay, so this is why we need to convert it to an integer. So n here, we'll just add the parentheses and we're going to write int, close that, save that, and this should convert it to an integer. But as you can see, 35 when we want to, by 2006, when we want to set. So with that done, I hope you enjoy it. I hope you're enjoying the course, even though I make a couple of mistakes sometimes I really like to keep them in here. And because I think it really, especially if you're a beginner, you can get very overwhelmed, but by what's happening. So you might think that, oh, how does my instructor do so well, and where does he get all that knowledge and why can't I be like that? I like to show you that I always make mistakes. I always have to go back and even sometimes cut long, long takes because I'm not sure what's the problem. I go test, use debug. I always go back and see where the problem is. As you can see, sometimes we even forget what, what, what's the variable that we're using. For that said, I hope you are enjoying if you are do leaving a review at helps me out a lot and lets me know what you think of the course so that none in the next video will be accessing our inventory and making the buttons of buying and selling, working properly. So I'll see you in the next one.
72. Making Buy & Sell Buttons Work: Welcome back my fellow game developers to a brand new video. And in this one, we finally finished buying, selling items. So if we go into the shopkeeper, we picked up some items. Of course, we still have a bit of things to fix. Like for example, on the right now when we open up the shop menu, we had the bypass and open. We need to turn it off. But those are small details that are not that important, especially when it comes to the code. So we open up the cell, we select the Golden Axe, we sell it and it disappears and we get 18. So we select, if we try to sell it again, as you can see, we can't. If we go to the portion, it's five, we should have 55 bitcoins. And if we solve this, which is 26, I think we get 780 something, 81, there we go. I'm not that good at math. If we tried to buy, let's say I buy the golden Ax Ay by the golden armor before I go to sell it. There you go. I can sell them again because they are added to my inventory and not just in here. If I go out, I walk away. I opened the items menu. I have them right here in my items menu, ready to work to go fight monsters. So Jimmy now can go to a shop. How cool is that? A demon can finally go and buy, sell things in the shop. That's unprecedented. So on that bombshell, let's not waste any more time and let's get started. Oh, time 40, last stage of our shop. We want to actually buy and sell items. So let's go into our shop manager in here. And we're going to create two methods. One for the buying and the other one, well, obviously for the Summit. So let's go in here and we're going to create a public forward by item. And we are going to check, first of all, if we have the amount of Bitcoin required. So if game manager dot instance dot, was it called the current hip, current Bitcoins is greater than or equal to the selected item dot value in coins, then we can proceed to buying and how do we buy? Well, first of all, we need to remove from the current Bitcoin. So minus equal the selected items value. So first of all, you know, when you buy something, you need to give something in return. And then we need to add it to our inventory. So inventory dot instance, dot, add items, and we're going to add the selected item to it. There you go, save that. And this should finish up everything in the back end of the programming. Now on the front end, we want to make sure that we update the gold that we still have. I mean, update the Bitcoins that we have. What ashamed calling Bitcoin gold. Anyways, even though it's much better. So let's continue on. So we have to update the text because I still remember, was it just the value? Let me see the amount of Bitcoin, okay, So BTC two points, okay, so BTC two points, we're going to concatenated with a string, which is going to be the game manager dot instance, dot bitcoin, bitcoins, and there you go. I think that's all that we need to do. We will save that. And now we need to assign this method by item to the buy button. So in the shop menu, in the bike panel and the buy button, if we scroll down, we know we don't want to open the character. What's that? We need to go in here? The shop manager, by, by, by item. There we go. Save that, run the game. If you open the menu, go to Items. You can see that we don't have anything and it still doesn't close when we hit close that so easy to do and we haven't done it yet. So we open up, you go to the menu, we buy the acts, the Golden Axe. And we can write, because we don't have sufficient funds. A message in here would be very nice, so we can buy candy by the golden. So let's buy a silver armor also, we still have seven Bitcoins. We exit shop, we go to the items and there you go. So now how cool is that? We can actually buy items and see them in our inventory. That is so cool. Okay, great. Let's go back. Now it's time to create the cell button methods and there's going to be part of your challenge. Your challenge is to create the cell button methods. So update the current gold. Why did I keep it as gold? Let me change that. Bitcoin, welcome to the backend of our world. So current Bitcoin with the value of the items, remove the items from the list, update the text, and set the selected item to null. And I'll tell you why in just a bit. But for now, go do the challenge. Okay, welcome back. So public void cell item, I really hope that you are doing the challenges because they are great way to learn. If to this point you still haven't done at least 50 percent of the challenges from this point on. Because this I think is the final section for final video. In this section, you have to put in the effort and do every single challenge. So the current Bitcoin will increase by the value. So it's going to be an int. We want to convert it to an end. And let's just copy this right here, because it's pretty much the same. So copy, paste it in here. So selected item, dot value and coin times 0.75. Okay, great. And then we are going to remove it from the inventory Door instance dot remove the remove item, the selected item. And finally we need to update. So we're going to get the text, paste it in here. And as I've said, we are going to set the selected item to be equal to naught. And why am I doing this? Save and let me show you why. So I'm going to comment it out. If you go in here, if we run our game, we pick up an item, we go to sell it. We can sell it. It's not updating. Why is it not updating? Because we haven't assigned to the cell button. The cell item. Where does it sell items if that run the game again. And this is very important. So we come to cell, hey cell, this is for 2006. We sell it. There we go. We get 58. And we can solve it out a lot, a lot, a lot of times. So what do we need to do in here? We need to set the selected item to null. And then we are going to create a if condition in here that makes sure that if there is a selected item or there isn't a selected item, we can do this or, or only when there is a selected item. So on the, when there is a selected item, then we can go ahead and shop. So let's try this again. Make sure run the game. This shop we want to sell, sell this item. There you go, so we can sell it on the ones. But if we click on it again, even though we can click, Okay, so we can, once, there we go. We can't anymore. And this is the final, let's say chink in the armor. So we are going to I'm not sure why I called chink in the armor. We are going to update the menu. How are we going to do that if we go one of them. So in here you can see that we are updating the items, so we'll just open cell panel again. So open cell panel. Now you can see that when we sell one of the items, there you go, selling, we hit this cell. You cannot sell it anymore. You cannot select the item and you cannot press the cell as much as you want. That's a solid once you get your Bitcoins and you leave to go conquer other villages and so on. So I hope you're enjoying the course. I hope you enjoyed the shop. I know there's not a lot of battling and game mechanics, but it's very, very important. This is more focused on coding, on how to avoid certain things, on how to create interesting environments if you want, and how to handle reactions between multiple scripts. So I hope you are enjoying, I hope your brain is starting to hurt because of all the ways that we've connected our shop manager and shopkeeper and item buttons and the inventory and the items manager and the menu manager and all of that, all of that are connected together in a beautiful way that seems to always be working. So I hope you are enjoying and I'll see you in the next video.
73. Section 10: Creating Quests: Welcome back, my fellow game developers. In this video, as you can see, we've created a quest manager with a couple of quests that we have in him and Quest markers. So when we run our game, you will see that for each of our quests, we have an element or a o k, time for some quests. What RPG doesn't have quizzes? Is it even an RPG? If there is no quests, maybe there is, I don't know. Let's create a quest system and let's show you just a little bit how this going to work. So this is one of my more professional drawings as you can see. So we have a rope, a dirt road, we have a cave with an entrance and some grass. And we have Jimmy, where the eye has become red. And we have the quests in here. So let's say we have three quests. 1, we need to kill the dragon, get the sword, save the town. Okay, so we'll have a kind of a checkbox system, so we'll have to collect Dragon will check. When we do kill the dragon, some kind of cave and another scene will open up and that gave will have a sword in it so we can go into the cave, get to sort, and then maybe go to another scene. And that's why I created this perfectly shaped arrow, which says, after killing a dragon, we can come from this place. Maybe the arrow should have been pointed the other way. But anyways, we come from another scene. We find the cave where we need to get the sword. We get the sword. We go back and go save the town. I don't know. Anyways, we'll get established. Let's go ahead and first of all, start creating the quest marks and the requests, which will have. So let's go into Unity and we'll go into the scripts, will create a new folder in here. And I'm thinking, Where should I put my camera controller, game manager, and menu manager? Let's create a folder. Oh, that's, that's a C sharp script. Delete. Let's create a folder, which we'll call the whereas the folder. Okay, so it needs a bit of time to process the folder. We'll call it the managers. Managers. So the camera controller is also a manager. And we'll just put it in Manager for now if you find a better name for the folder or a better place for the scripts, will put them there. And we'll create a new folder. And the scripts for the quests and y is unity. So slow quests, I go red. Let's save that. I feel unit is about to crash. So inside of the quests, we are going to create a C-sharp script which we'll call the manager. Enter, wait for it to compile, and the cost manager will be added in the game manager because obviously that's the best place to save a cost manager, as we'll be going through multiple scenes and we need to keep track of requests. Okay, great, with that done, let's save, and now let's open up the cost manager and Visual Studio and see what we need to do in here. So first of all, we need the names. So we're going to go ahead and create a serialized field where we are going to create an array of strings. And because it's not a list, because we won't be removing or adding anything. So it's not a problem to keep it as an array. And it's going to be the quest names. We're going to create a, another array, but this time it's going to be of Booleans and it's going to be the quest markers complete. So these will be the markers, as we've said, we'll have markers for each of the quest and we'll have an aim. So let's go ahead and save this. Save this, go back into Unity, and let's add a couple of quests. And let's see. So we have requests complete and requests name. Let's go ahead and start adding a couple of quests. Will leave the first one blank. And we'll have maybe four, maybe five. Let's see. So what should we have in here? So defeat, dragging. Sure, why not? Let's say we just enter a cave. Just, just entering a cave solves one of the quests. Maybe this should be fine. The cave still a jam. Take monster, so take monster sold. Okay, save that. Now the next thing we need to do is we need to create this quest markers complete array. And the way we'll do this. And as you can see, we need to make this a big C save that now will have markers completed. Okay, so now we need to create the quest markers completed. And why do I say Create and not just add a couple of markers in here, just like we did for the names. Well, because we don't want to go ahead and create these markers manually. We want that to happen automatically. So we want a way whenever we start, let's say the cost manager two, create this quest markers complete and it will be the same length as the quest name. So it's going to be part of your challenge to create an array of bulls. So set the completed cost markers array as a new array and start. This array should have the same size as the array of quests we've created. I'm going to give you a hint. If you don't want to listen to the hand, pause the video right now and go do the challenge. And less chance, you'll need to create just a simple syntax of equal new boolean with the length of the quest markers name, or this should be the request names, whereas this was a old name. So pause the video right now and go do the challenge. Okay, welcome back. So as we've said, and start, the quest markers completed is equal to the new bold. The size should be the cost. Markers names, dot length. Save that. Back in Unity, we run our code and we should have in here, yep, there we go, four elements for each of the requests that we have. So this was a very simple video. We just are laying down the groundwork to start going to the next level each time with our quest system. So I hope you enjoy it and I'll see you in the next video where we'll be creating code that will actually check for these molecules.
74. Marking Quests: Welcome back, my fellow game developers. In this video, we are just going to create ways in which we can check and uncheck our quest markers. So currently if I run our game, if we check the, let's say the second one and the last one, if we hit the Q key, you'll notice that the last one was turned off. The element three, which is still jumps, was turned on and we get a false. But if we click on the first one had dequeue again, you'll notice that we get true because we're checking if the defeat Dragon Quest has been complete. So let's not waste any more time. We just need to create a couple of methods and let's get started. Oh, okay, SOL, time to check our quests for complete and incomplete. How are we going to do this? Well, let me explain with a very professional drawing. So first thing we're going to do is we're going to check for a quests number. So we want a way or a method where we can give it a quest for requests name. It will find the position of that quest in our quest log. And then we are going to check if that request is complete. When we finish checking if that request is complete, we can either market complete. All we can mark it incomplete. I know I've been at 18 here, but that's all that we need to know with this little cool drawing. So let's get started implementing this into our game. So first thing we're going to do is we're going to create a method in here that's going to check for, for actually get a get request number. So this will take a string and it's going to be a string for the quest to find. And how are we going to get the number on which the quest resides? This is going to be part of your challenge. Your challenge is to get the quest number. So you'll need to loop through all the names we have. You'll need to check if one of these or one of the costs is equal to the quest we want to find. You will need to return the position. And if we don't find the cost that we want, you need to print out a warning. And the way you print out a warning is by using the debug dot log warning. So with that information, pause the video right now and go do the challenge. Okay, welcome back. So in here we're going to create a for loop. It's going to be int I equals 0. While I is less than the quest names dot length or yeah, names dot length. And we're going to increase each time. We'll open up the brackets and in here we'll check if the quest names at position I is equal to the quest to find, then we are going to return I. And if at no point we return in R, and some of you might have got this problem. And here's all the Quest marker because it has a return type of int, there needs to be a return, and not all code paths return a value. So for example, let's say we loop through all the Quest names and we don't find any that have the same name as requests that we need to find. There will be no return and that's a big no-no when it comes to return types using methods. So what we'll do is we'll simply return 0 and that's why we have the first quest as an EMT and debug dot log warning quest to find those not exist. Save that. Okay, so now this must method loops through all the names and checks if one of them is equal to the cost that we want to find. Next, we're going to create a method that checks if the request is complete. So it's going to be a public bool check. If complete. And it's going to take a string argument. That's going to be also the quest to check. And what are we going to do in here? Well, we're going to first of all create an integer. So it's going to be an end, the cost number to check. And we're going to use the newly created method, which is get, GET request number, and we're going to send it the quest to check. So now we have the position of our quest to check. Then we're going to create a condition. And if the quest number to check is different than 0, because if we don't have any returns will get some kind of warning. So in here we need to make sure that it's different than 0. We're going to return the quest markers complete at the position of the quest markers number to check. And finally, if we don't get anything, we will return false. So if you're still confused about how this return will work, well, let's say we start off, we get the number by using the method we've created up here. So now we've got the number of the quest to check. We then make sure that it's different than 0. If it is, then we are going to return something if it's not. So what happens in here when we return this and here the quest markers complete at the position that we wanted to find. So it's either true or false. When we return, that's it. The method stops continuing. If we don't, the method will continue on and we will return false. So let's save that. And finally, the final two methods which are the quest complete or where we are going to mark the quest as complete or we can mark it as incomplete. So maybe we want to turn back the question. Maybe you somehow reverse the quest for some reason. I'm not sure why, but it's good to have one of those available. So finally, we are going to have two public methods which are going to be void. And if you want, you can go ahead and create these on your own. They're not too hard. Mark Complete. And it's going to have also a string which is going to be quest to mark. And we're going to end here, go ahead and get the number to check. And it's going to be the quest to mark. And we're going to Quest markers completed at the position Quest, quest number to check. And it's going to be equal to true. That's because we're checking it as complete. And we'll create a second method in here, which is going to be two quest marker or mark Quest, I'm sorry, incomplete question. Mark. Everything in here is true except for this, which shouldn't be false. Okay, Great. Finally, I know that's a lot of code without testing anything but all of us as worth it. It's not very complicated. You can look through it again. There is nothing. So we're finding the number. We are checking if it's complete. If it is, we'll mark it as complete or we can mark it as incomplete. That's it. There's nothing too complicated in here. Finally, we need to create a way to check one of the methods. So we'll create an if condition in here will take in an input dot get key down. And we'll use a key code. What should we use? I think Q for quest. And before I forget, when you want to build your game, you need to remove all these inputs. So we're going to print out, first of all, check if complete. So we're going to check if a certain quests that you want this complete. So which costs do we want to check? Let's go back in Unity and let's check for defeat tracking. So we're going to copy that. We're going to paste it in here, and that's a string reference. You need to make sure that it's correct. We are going to mark the quest as complete, and we're going to send it the another one. So we're going to send it the enter cave or still the gym. So we're going to mark these still the jump quest as complete and will mark one of those as incomplete or complete when we start our game and then we will mark it as incomplete is going to be the last one. Well, we take the monster sold. So Mark and complete, open that up based in, in here. Save that. And let's go ahead and run our game and see how it works, okay, Just making sure we'll run our gain. So we're going to check the last one as complete, and we are going to hit the Q button. There we go. You can see that first of all, we check if the defeat dragon is complete. So nope, it's not complete. In here you can see that we stop the completeness or the monster sold or take monster soul quest was complete, but when we hit the Q cold, we marked it as incomplete while the steel jam, which is right above it, was marked as complete. Now if we try to turn the first one, we should get a true in here, and this should be turned off. So we hit the Q, we get another false yet because we should have checked this one, not the last one. So now we should get a true hopefully. Yep, there you go. We gotta true, everything is working. We are checking our quests. I hope you enjoy it and I'll see you in the next one.
75. Quest Objects: Welcome back, my fellow game developers. As you can see now we have a map and we have a jump. But whereas the jump there is no geminal map, how's it going to appear? Well, if we run our game, we have a special button that will make the jump appear. It's G way, it's not working. Why is it not working? Oh, because still the jam hasn't been turned on. So if we turn it on and now we hit the G. Yeah, there we go. You just saw the jam appear. So let's not waste any more time. And let's create some quest objects. 0 case. So how are we going to use objects and all quests? And how are we actually going to implement all of this? Let's first of all, see if we have anything to commit. Yep, there we go. We need what did we do? We added the ability to check quests, that, and let's see how it's going to all work. So let's say Jimmy is traveling around. He has no idea where a certain object is. He goes through the same place once, twice, three times. But finally, he picks up a kind of a map. And when he does pick up a map, goes to the same place, he finds a jump. So what we'll do, we'll, what we'll do is we're going to create a way, create objects like the map that when we pick them up, for example, a certain quests will be marked as complete. And when that quest is marked as complete, then the jam, for example, will appear. Okay, so I hope that wasn't too confusing. Let's get started. So we are going to first of all, open up Unity. And in our scene we'll just add a jump somewhere in here. So I'm going to look through for some kinds of jam. Yep, this red gem will do it. And we'll make these private as background. Then come up. Player. There we go. So we're going to scale it up to three. And yep, there we go. We can even make it a bit bigger. Let's make it five. It's an important jam to find. Okay, so this jam, as in the waters, Let's say, okay. I'm not sure why it's in the water, it's underwater. And then we are going to go ahead and create a script in here, which is going to be the quest object. So in the scripts, in the quests, we're going to right-click create a C-sharp script is going to be the quest object. Wait for that to compile and we're going to change this to the red gym. And we're going to add the cost object to it. And we're going to open it up and the script. So what do we need? And here, we need three variables. First of all, we need to check for the object to activate. We need a string for the quest that we need to check and a Boolean to make sure whether we want this to appear or disappear when we pick up something. So why do we need to disappear? Let's say, for example, a cave is closed. When we, for example, save into town, we want that cave to open up or for some rock to disappear from in front of the cave and then we can enter it. So we're going to create a serialized field. It's going to be a game object and the object to activate. Then we'll create another serialized field. And it's going to be of type string and it's going to be the quest to check or to complete. I'm not sure you can call it whatever you want, whatever makes you comfortable for you. And finally, we need to create a serialized field that will turn it on and off. So activate if complete, save that. Okay, now we're going to create an instance of the cost manager. So we're going to create a public static quest manager. And we're going to create an instance. Save that, and then start instance equals this. Okay, great. Now back in our quest object, we are going to create a method to check for completion. Us just delete the start and update for now. So we're going to create a public void, check for completion, and we don't need any parameters. What we'll do in here is we're going to create a condition. And in here we're going to access the quest manager don't instance. And we're going to check if complete. So the quest to check, which we have already established and here the string. And we're going to get the object that we want to activate. And we'll set active. Active, F complete. So the object that we want to set active, whether it's a cave door, the jam or anything else. Then we're going to create and update a wave for us. So it turns out that we do need update and an update to just create some kind of key. And if input dot get keydown, keycode. And jam, jam is, gee, I hope it isn't used and any other place, check for completion. Okay, so what happens now when we hit the G key? We will go to check for completion, will check if the request is complete, then the object will be set to active. So let's go back into Unity. And in here, Let's see what we have. The object that we want to activate will be the regime. Now as you can see, this is not the best place to put this object. We're going to check or activated complete. We'll set it to an active so it will no longer appear and requested. We need to check, let's see In Game Manager what we have. Still jump. Sure why not? So steal the gym. Make sure that you copy and pasted correctly. Now we'll run our game software walking, we're walking, we're walking. And if we hit the G key, nothing happens. That's because if we look at the game manager, the steel, the jam isn't working. So if we hit the Q, it will turn on. And now if we hit the G, nope, it's still not working. Okay, So the problem is that the red gem isn't even active, so we can't really access the request object. That's the whole point of it. So it's inactive. We need to set it to act. So we'll do something different. We'll add a where is it will go to the items or not the items I meant in the sprites environment. Let's see, we have a map in here, somewhere. There you go, There's a map. We'll edit in here. At the map here, where is it? Smooth it up. That's set the sorting layer to the player. Scale it up to two. We'll add a small box collider around it and we will make sure that it's a trigger. And we're going to get the red jam. We're going to copy the component, will go to the map. We'll add a component which is going to be the cost object, will base the component as we can paste it as num. Okay, so we'll just remove this component. There you go. So now the object to activate is the red jam. Still the jump activate, complete. And we are going to remove this from here. We don't need it. Save that. Now if we run our game, we will try to turn on the jump. We can test because in the game manager, the element isn't complete. If we completed, there you go, the element appears. Now if we hit the G key, There we go. So now we have the jam appearing. Very nice. Now there are a couple of tweaks in here that you can do. For example, you can turn on an object when you actually pick up the map, for example, you destroy it. You can add it to your inventory. When you have it in your inventory, you can do stuff with it, but this is just the basics of how our quest objects are going to work as we move forward. So I hope you enjoyed this very simple quest object system, and I'll see you in the next one.
76. Completing Quests: Welcome back, my fellow game developers. In this video, as you can see, we have a knot hidden gem. So when we run our game, if you remember, the Q button finishes the steel gem quest. So when we hit the Q button, as you can see, one gem disappears, the other one appears. So in this video, we are going to be able to complete our quests more dynamically using the quest manager. So let's not waste any more time. And if you're enjoying the course, as always, make sure to leave a review. It really helps me out and I know what you think of the course. So let's not waste any more time and again, and let's get started. Oh, okay, so now we need a way to check for the completion automatically and dynamically. We don't want to, every time we want to check for if something is complete to hit a certain key. To do that, we need to access the quest manager. So in the request manager, we want to go through all of the objects that we have and to check for completion every time we mark as complete or incomplete. So we're going to create a new method in here is going to be a public void. So public void update request objects. And this will make sure that all of them are either appearing or disappearing. So because it's that easy, I'm going to give it to you as a challenge. So find all the objects of type quest objects. Make sure there is more than one loop through all of them. Check if they are complete or not. Call them in both methods where we mark our quests. So pause the video right now, read the challenge again. If you didn't get what you should do and go do the challenge. Oh, okay, welcome back. So in here we're going to create an array of type request objects. And it's going to be called the quest objects. And it's going to be fine objects of type. So objects, not objects, objects of type. And it's going to be of type, of course, quest objects. Then as we've said, we're going to check if there's more than one. If there is none, then we don't need to do it and avoid any errors. So quest objects dot length greater than one, greater than 0, I mean. And in here we're going to loop through all of them. So for each request, object, request object, just keeping it simple and quest objects. There we go. What we'll do is we'll access the request object. And we're going to check for completion. That's it. There we go. And finally, what do we need to do? Call them and both methods where we mark our costs. So where do we mark our requests in here? What was the method called update cost? So update request objects and update cost objects. Okay, with that done, finally, we need the Q2, Okay, So at marks as complete that we stall the GMP. Okay, great, So let's opens up. We are going to duplicate this jump. We are going to, whoops. Where's the second jump? Let's put it up here. Let's turn it on. And what we'll do is we'll add the, okay, so we removed, let's add the quest object to them. So in script and the quests, let's choose them again. Quest object. The object in question is this one. And for the second one, it's this one. The, where is it? Where's the game manager? Still gem? Paste it in here. And this one will activate the complete while this one should deactivate or so it should deactivate when completed. So we're going to save all of that. And when we hit the Q button, if you remember, we set active to the still jump. So when we run, hopefully this right now, when we hit the Q, there we go. One of them turned on and the other one was turned off. So how cool is that? Now we have a way of accessing the game objects and always making sure that they work automatically without us having to press any extra keys after finishing request. So I hope you enjoy it and I'll see you in the next video.
77. Activating Quests: Welcome back, my fellow game developers. As you remember in the previous video, we've made our quest system a little bit more dynamic. Now it's time to take to the next level. So when we run our game, as you can see, one Jam as very fine, We can see it, the other one is disappeared somewhere. Where could it be? Well, let's try to pick up this map Wo, as you can see, we found the second gem. How cool is that? So let's not waste any more time and let's get to automating our quest system just a little bit more. Okay, so now that we can activate and deactivate or turn on and turn off game objects based on quests dynamically, it's time that we activate a quest when we enter a certain space or zone or so on. So what we'll do is we're going to create questions. So we're going to go ahead into the map that we just created in here, the box collider that we had. And we are going to delete it. We are going to already know what we can keep it if we want. And we'll remove the request object for now, remove component. And there we go. And we'll add next to the map quest zone. So this map is a quest zone and when we enter it, there are things that cone to happen. So create C-sharp script, and we'll call this the quests or wait for it to compile. And we're going to add it to the map. And we're going to open up the quiescent zone. So what are we doing in here? We are looking for two types of cost activators. The first one is if the player simply walks through the struggle place, we immediately start the quest. So for example, let's say we walk through a certain zone and the monsters appear. The second type is we want to talk to a certain MPC and get the quest from them, and then we'll start the request when we can stocking. So these are the two types of costs that are usually found in gains. So we'll need a couple of variables in here. So serialized field is of type string and it's going to be the cost to mark than a another serialized field, which is going to be of type bool and it's going to be Mark as complete. Then we'll create another serialized field and this is going to check whether its mark on Enter. So it's going to be bool, mark on and TR. So let's say we have a quest where we have it mark on Enter. So when we enter, a cave, request is complete, and then the jama peers, for example, it's out of the top of my head. And then we'll have a private boolean. And that means we can mark because as we said, this is a Trigger Enter. Oops, just gave away the challenge. I mean, it's a trigger. So back in our code in here, what shall we be doing? Let's just delete the start and update. I say that every time and every time it turns out that we do need them. So let's get started. First of all, what do we need? We need to create a method that marks the quest. So it's a public forward mark quest. And in here we're going to check if the mark as complete. Then we're going to access the quest manager. We're going to access the instance. We're going to access the mark quest as complete, as complete. And then we're going to give him the question mark. And if it's not marked as complete, then we're going to do the same, but instead of Mark as complete, we're going to market as incomplete. So this might come up as not very useful. Why are we marking certain quests as incomplete? But later on when you play the game, you'll notice that some quests do need to be checked as incomplete. So for example, let's say, what can we say? For example, for some reason we want to leave the area, then that marks it as incomplete. We want to remove any kind of jumps that are there. Or maybe we want to if we pick up the wrong sword or something, I'm not sure, but it might come in handy. It's it's good to have this as some kind of debug and your game. The next thing is to create an entrepreneur enter that checks for everything and I'm going to show it to you as a challenge. So your challenge is to mark a quest. So create an entrepreneur. Enter 2D, check for the player tag. Check if these aren't as mark on complete. So some zones need to be marked on complete, as we've said. Others. Or mark on Enter Amin and others are marked when we start the dialogue. If it is simply mark request should be simply not simple. And if not, this should be not, not. Now, check the Boolean can mark, well that's pause the video right now and go do the challenge. Okay, welcome back. So on, Trigger, Enter 2D, scroll down and we're going to check once again, I think we've done this seven times maybe.com tag player. And here we're going to check if its mark on Enter. If it is, then we are going to simply mark the quest, our method and here. And if it's not, then we're just going to say that can mark is equal to true. Save that. And finally an update we are going to see. I've told you that we need to always be creating updates. As I scroll up and see that I again Remove update. So in here we'll just use the can mark. So let's say it's some kind of lever that we need to push. The lover can only be interacted with if we are in a certain position and when we do triggered when we are in the quasi zone, that means we can mark. And if we can mark and we press the fire one, then the cost is complete and something around us happens. So if we can mark and input dot get buttoned down, I want to use the fire 151. Then we are going to can mark equals false. So we don't trigger the cost again or have some kind of weird thing happened. And then the mark Quest will work. There we go. And there is one more thing that we should consider and that is if we want to turn off the zone entirely, or in the case of our map, for example, destroyed. So when we do have the map, we said we don't need to have it in our inventory. You could have the new urban story, but what if you want to destroy it? So we're going to create a variable in here which is going to be a public pool and is going to be to deactivate on marking. So this will activate the zone on marking. And in the mark quest, after we check whether we mark the quest complete or remark the quest incomplete, the game object. Dots are active will be the opposite and y is the opposite of deactivate on marking. Why is it the opposite? Because if we do want to deactivate on marking, we set to true. And if it's set to true, then we need to deactivate. That means we need to set active to false. That's why this is negated with an exclamation mark. Save that back in our game. Which customer do we want? We want the jam. So still the JAM, copy that, paste it on the map and Barker's complete mark on Enter and the activator marking save that, run the game. Let's look at our gems appear, see if they disappear. So now we walk, walk, walk, and now when we enter the map, this chance should disappear and this one should appear. So hopefully, Yep, There we go. The map disappears, the jam disappears, the final GM doesn't appear for some reason. Why is that? Oh, Kay, why did it not appear? Because oh, the problem is that the jam is inactive, so we are not finding the object. So to circumvent this problem, what we'll do is in the red jam or the first truck jumble right-click, we'll create an empty game object. This will be the quest object, will remove it from the child and then add the red jump to it. So now the quest object is on the same position and we'll set it, will just keep it. So now what happens is we are going to copy this component, paste as new, and we'll remove this remove component. And this is what we should be doing to all of our quest objects. So now when we look through all of our objects, we will find this quest object, and then we will turn on or make the red jam appear. And finally, we need to make sure that it's the red jam that we want to activate and here. So if we save all of that, if we now run our gain, the jump that has been not appearing should appear. So now we walked to the map and there we go. One disappears, the other appears, and everything works perfectly fine. So I hope you're enjoying so far how the quests are working. We are slowly building from the ground up and doing everything dynamically. The final piece of the puzzle is activating quests when we finish dialogue with certain MPC's. So I'll see you there.
78. Activating Quests After Dialogue: Welcome back my fellow game developers to a brand new video. And this video, when we run our game, you'll notice that we have one jam appearing, one is not there. So we go to the healer. Hey, healer. We talked a bit. There you go. So when we finished the conversation, the gym disappears. This Gemma appears and we have activated a quest object after we finished talking to a healer. How cool is that? So as you can see, we've created a really nice dynamic costing system. So let's not waste any more time. And let's get started. Oh, okay, So now it's time to mark a quest as complete after we finish the dialogue with a certain character. Now you can add a another option where you can choose whether to accept requests or not. I recommend that you try that. But for now, let's just stick to the very basics where we just make sure that we have a Quest at the end. So what will do that me just take you through the plan real quick. We're going to add to the RequestHandler a way to check that at the end of the conversation we activate some kind of quest and then on the dialogue controller will actually activate a certain question. Okay, so let's get started. First of all, let's go into our code and let's go to the dialogue controller. Where is the dialogue controller? There is no dialogue controller that we close it somewhere. So you dialogue Controller. And let's open the dialogue controller up. Okay, there we go. So a couple of variables in here, and they are all going to be private because we are getting them all from the dialogue handler, which is on one of the MPC's. So let's say private string quest to mark than a private boolean, which is going to be more of the quest complete, Mark Complete and could be false if we want to mark the question incomplete, for example. And then another Boolean that is v should mark west. Okay, so now we need to find where we finished the dialogue and actually start checking and marking the quests. So we finish the dialogue after all the dialogue sentences have completed. Okay, so we turn off the box collider. We turn off the dialog box is open. That's for the player to start walking again. And in here we're going to check if we should be marking a cost. So if we should mark request, then the short mark requests should be set again to false. Just like we did previously. We just stop the can mark. We don't want it to continue. Then we check if we want to mark the quest complete, we are going to access the game manager dot instance, dot mark as complete. And we're coming to, of course, give it the game manager dot instance 0. So we need to go to the cost manager. I thought having a lot of managers can really be confusing. So instance dot, get or mark quest as complete. And it's going to be the cost to Mark. And else. Obviously, we could have done this without the brackets, but no worries. Let's just copy this. Mark. Incomplete. Save that. Okay, great. So now what we do, we check if we should mark a quest. If we do, we uncheck it. We don't want to go through this again. If the mark is complete, we check the question mark. Else we check it as incomplete. Okay, great. Now we'll need a method that activates at the end. So we're going to create that mattered, that activates the Quest at the end. And it's going to be part of your challenge. Your challenge is to activate the Quest at the end, I thought I've said this sentence already three times. Create a method, activate Quest at the end that takes in two arguments, a string quest name and a Boolean Mark Complete and set the variables we created. So what will this method even do? Well, because as we've said, we'll be calling, we'll, we'll leave the quests to complete to the actual NPC we don't want to deal with in the dialogue controller. We want to do it in the dialogue handler. So this will allow us to talk to the dialogue handler and set all the variables which are private. So with that explained, with the challenge in front of you, pause the video right now and go do the challenge. Okay, welcome back. So in here, let's add. Method right under the update. And in here we are going to create a public void. Activate Quest at end. And it's going to take two arguments. We said it's going to take Quiz Name and Mark Complete Boolean. So the quest name and the Boolean Mark Complete. And in here what we'll do is the question mark will be the hostname. So it was Tamar is equal to the hostname. The mark was complete, is equal to the mark complete. So if this one is false, the more complete will be false. Okay, so we just use the same one, mark request as complete. Let's copy this. So variable naming is very important. And finally, this should mark quest should be set to true. Because if we sent anything at the activate Quest at, and then of course the should mark quest should be true. Okay, great. Now we need to go to the dialogue handler and do almost the same thing. So whereas the dialogue handler, there you go, That's the dog handler. So we are going to create three serialized fields because they will be dependent on what we choose for this character to Sam during the conversation. So Boolean should activate quest and other serialized field because it's going to be a string, which is going to be the quest to Mark. And finally, serialized field with the Boolean mark as complete. Complete. There we go. And we're going to go and update when we pass on the sentences. We are also going to check if we want to actually activate the quest. So if we should activate a quest, then we're going to access the dialogue controller. Where is it Okay, Darla controller dot instance, dot, activate. And it takes in two variables or two arguments, parameters even you can call them so the hostname and the Boolean mark as complete. So the hostname is the question mark, and also the mark as complete. Save that back in our game. Whereas Sarah, you forgot about Sarah. But again, she always has some job to do. Again. So where is it the dialogue handler? We can change the sentences, but, but let's keep them as they are right now. So let's make this a bit bigger. So should activate a quest. Yes, you should. Should mark as complete. Yes, she should. We, whereas the manager still the gems. Pass it into Sarah. Sarah, Sarah's. Okay. So the question mark is the steel, the jam. We'll save that, we'll run the game. Let's hope this works. Let's go up to Sarah. Hi Sarah, I'm a healer than Ananda taylor. There we go. So as you can see, I didn't notice, but it did work because this gem disappeared. This gem appear and it's just because we finished the conversation with our healer. So we have finished all the costing system. We've created a very nice dynamic one which turns on and off after conversations and after we pick up objects. So only your imagination is the limit here. You can use this for song, so many things. So I hope you're enjoying this course. I'm not going to remind you again because I've done it a couple of videos ago. So you know what to do a literature review. I would love to know your opinion and I'll see you in the next one.
79. Section 11: PlayerPrefs: Welcome back my fellow game developers to a brand new video where we do something very dramatic. We actually almost destroyed the entire map with our new amazing abilities. So when we what if we had the icky race for it? Yep, that has been saved. I know it's a bit underwhelming, but let's not waste any more time, and let's get started. O k. So now we can do a lot, a lot, a lot of stuff in our newly-created RPG. But as you know, every single RPG has a loading and saving. So what's the point of building up your character if you can't even save all the progress that you've had with that character. So saving and loading is a very, very essential part of an RPG game, and we'll do just that. So the first thing that we need to do is understand how saving and loading works in unity, and that's through player preference. So let's explain what player preference is. Let me put on my laser and what is Player for reference or player prefs. It allows us to store certain data like strings, integers, and floats. So these are the only three types that we can store it in player prefs. Now you might be asking, Well, Michael, how are we going to be able to store, let's say for example, items or quest markers, Booleans. How are we going to do this if we're only confined to strings, integers, and floats. Well, don't worry about that younger grasshopper, because we are going to find very creative ways of solving these types of problem. This data can be accessed between sessions of game-playing. Data is identified by a string key. And I'll give you just a couple of examples just to wrap your head around it and it not being very scary. So we just set an integer, we give it a key, just like we said in here, it's identified by a key of type string. And then we set the value an integer because we've settlement. And then how do we load that player prefs? Well, we use the get and using the same string key that we've added for this NFO right here. So let's start implementing all of this and it will seem much easier and much less scary. So we're going to open up Visual Studio and we're going to go to the manager. So let's open up Visual Studio. Let's go to the legends of conquest 2D. And okay, great. We're going to go to the quest manager because the first thing that we want to be saving our, our quests. So how are we going to save player quests? Well, first off, we need to create a key, and that key will be the name of the costs that we want to tackle. And then the value will be an integer or an end that will represent either a false. That means we haven't completed the quest, or a true, which means we did complete the quest, but how are we going to represent this false and true? Let's delve deep and see how that goes. So first off, we're going to create a method in here. And it's going to be a public void. Save quest data or that, I'm not sure what you want to call it. So save request data. What are we going to do in here? We're going to go through all of our quests. Check. So we're going to first of all create a loop going from I equals 0 while I is less than v. What was it called? The names, I believe the quest names dot length. These are all of our costs that we have. And we're going to increase by one of course. And in here we're going to check if the quest markers completed at position i. Then what we'll do is we'll call upon the player prefs. And if you're not sure how to use player prefs, I recommend that you go to the unit dogs. It's a great resource. I've showed you multiple times and I don't think going again, they're just for the player prefs. I do recommend that you always do your own research and don't just trust me, maybe I'm lying. Who knows? So we're going to set an integer. And in the year we are going to first of all create a string, a key, and then a value. So what does the string key in here? It's going to be the quest marker underscore. And then we'll concatenate it with the quest names. At the position I. And what's the value there? Well, it's going to be represented as true. That means we'll set it as one. And then later on when we're loading data, we'll use that in order to set it to either true or false. So let me just explain again what we did in here. So we are looping through all of our quests. We are checking if that quest is complete. If it is, then we call upon the player prefs. We tell it that we want to set an integer. And then we have this key right here. So to represent the quest markers, or you can say set it as Quest names. But because we are setting the quest markers. So the quest marker, and we want to be able to identify it individually for every single quest. So to do that, we add a bit of individuality by concatenating request marker underscore with the quest name. So you'll have a table where you have the quest marker underscore. Let's say for example, kill the demon, know we are at Lehman, kill the dragon. So quest marker underscore killed the dragon has a value integer of one. And then we will translate that back and create the Booleans, whether it's true or false. Okay, so now that we've set the true quest markers, it's time to set the false ones, the ones that we haven't complete. And that's going to be part of your challenge. Your challenge is to set the quest marker used player prefs to set the quests that are incomplete. Keep the string key the same and only the value of the int should change. So we've already, I think covered everything. Keep the same key because we are working, Let's call it on the same dimension where we are saving the quest so you don't need to change the key, only changing the value. So pause the video right now, and in order to set it as false equals 0, this is a hint, I don't think I read it. Pause the video right now, and go do the challenge. Welcome back. So in here we're going to say that else, if it's not complete, then we're going to copy this line. We'll paste it in here. We'll keep the same quest marker underscore quest name, but instead of one, because it's incomplete, It's going to be 0. And we'll see later on and more in-depth, how will translate this 10, a true and false. And finally, we need a key to implement this. So we'll go up and to update. And we are already using the queue. So if input get key down, keycode dot and we'll use some button we haven't used yet. I think I, so I, and if we click the I are going to debug dot log. And we'll say here that the that has been saved. This is just for debugging purposes. And then we are going to save quest data. And what's the pro? So get button, noun, get key down. That. Okay with you. Yeah, there we go. So save cost data, debug data has been saved. Let's go back into Unity and it should be compiled right now. So we'll run our gain. We're going to hit the I key, and there you go. Data has been saved. Now, this was underwhelming and nothing too obvious happened. But in the next video we will see how all of that works when we start loading the data. So I hope you enjoyed the video and I'll see you in the next one.
80. Loading Data : Welcome back, My favorite game developers. In this video, when we run the code, we do actually have something dramatic. If you look at the quest marks right here, we've completed a couple of them. So we want to load our data. We don't want to go over all of these quests and do them again. So we're just going to load the data. And you can see in here that data has been loaded and these quests have been complete. So let's not waste any more time and let's get started with loading our data. O k. So time start loading. There is a small problem when it comes to loading data. What is, the problem is what happens if we already have saved all of our quests, okay, so we have the quest strike now, we save all of them. But then during gameplay we add another quest. So then when we go to load it and look for IT, Ops, there is none and we cannot find it. And this will give us an error and we will be wondering, well, what the hell happened. So we need to avoid this by first of all, checking if there is actually any player preferences set using this certain key. So even though I told you I'm not going to go into Unity dogs, apparently I am. So I've opened up the player pref stocks and the Unity documentation. And in here you can read all about, you can even see where that saved and you can go check that out, see how the data is stored and so on. So if we scroll down in here, we can see that we have multiple static methods. And one of them, you can see that we have the get ND, get, float the safe, the safe flawed, save, and, and so on. And then we have something called the Husky. And this returns true if the given key exists and player prefs otherwise returns false. So this allows us to, before we delve into getting something, this allows us to check if there is something in there anyways. So we're going to use this one we are loading as a mechanism of defense against errors. Let's get started. So we're going to open up our quest manager and we'll create a method which is going to be the load request data, public void load data. Okay, so we're going to create a loop just like we did up in the save cost data. I'll just copy this line because it's exactly the same. Yep, we're going to paste it in here. There we go. And let's just remove one of those. What's the problem? Is there any problem? So apparently, when we paste just that, so we'll keep it as that will close the brackets in here. You need to keep count of the brackets. So what are we doing in here? After we run through all of our names? We're going to create an integer which is going to represent the value 2 SAT. And it's going to be equal to 0 because we need to give it some kind of value four, we continue one. And this squiggly green line means a warning. So the value set as assigned but is never used. And because variables take up a bit of space of memory in your computer. So Visual Studio always reminds you that you have an unused variable. You can delete to save up some space. Anyways, that was a site. Now in here we're going to use the player prefs. We're going to use the Husky. And we're going to use the key that we've added in here. So we'll just copy this line. So as I've said, first of all, we have the key. Then we have removed this in here, and this one also. There we go. So this will check for a king. And as I've said, these are the keys for our quests, represented by a word quest marker underscore and then concatenated with the actual quest name at position I. So we check, do we have a key which has the name quest marker underscore was the quest name at position I. If we do, then the value to set will be equal to player prefs, sorry for that player prefs dot get ENT. And how do we get an integer? Well, we use the marker on the score and the name. So there we go. That's all that we need to do. We only need to give it this quest market. Okay, great. So let me just go over one more time. What we're doing in here, we are looping through all of our names. We just created a variable in here to keep store the value to set. We've accessed the player prefs and looked for the Husky and checked if we have a key that has the quest name in it. Then we set the value by using player prefs dot get k0, and then used this string right here, which we can actually, let me show you one of the many uses of variables. So as you can see, we are using this marker plus hostname at position i 2 times. So a better way of doing this as writing a string key to use, and it's going to be equal to this right here. So we got that, paste them in here. And the way we cut is by using Control X. And in here we can simply use the key to use. And here also key to use. There we go. And this should be working fine because the key to use is at this position and make sure that it's inside the loop. So it always gets updated. Okay, great. Now that we've set the value, so when we get the integer at the key to use, which is this right here, we check, we get either a one or a 0 on, based on that, we are going to set the markers as complete or incomplete, or the complete as either true or false, just like we are using in here. Show you in here. So quest markers, either complete or not complete, and that's going to be part of your challenge. So your challenge is to send the request markers complete. So based on the value that we got, set the boolean of the quest markers. And just a small reminder, 0 is false, one is true. Pause the video right now, go to the challenge. Come back. So after we've set the value in here, we're going to go ahead and create an if condition. And if the value set is equal to 0 means we have a false and we can just remove these brackets. We don't need them because we only have one line because we're accessing the quest market is complete at the position I and we are telling it that it's equal to false. And if it's not so else. And you can, if you want to be more specific, you can use else-if value set is equal to one, just in case we have something different than 1 or 0 by mistake, but I believe you can keep it just as it is. So the quest molecules complete at position I is equal to true. Let's save that. What's the squiggly line problem? Nope, no problems. Save that back and update will use some kind of key. So we're going to duplicate this line. We're going to use instead of I will use the 0. So i, o and data has been loaded. And instead of saved data, we're going to load, load request data, save that back in our unity. Now when we run the game at opens up, we move around. Let's see what kind of in the game manager, let's set all of these to true. We're going to hit the icky, so data has been saved. Now if we turn all of them off, we hit the O key. Very go. How cool is that? We actually store data and then loaded it. How cool is that? And not even that, we have something much cooler if we run the game again. If we look down in here in the quest manager, if we hit the O key, how no, seriously, take a moment to think about how cool is that we've actually saved data. And you can clearly see that we didn't do any manipulations. It's simply beta that has been saved using integers. And not only that, we've converted integers into booleans by just a couple of lines of code. So with that done, let's go ahead and stage all. We are going to name this used layer graphs to load data. Load data to be specific, we're going to commit that. And let's look at the masters. Whoa, whoa, look how much we've already done. We've finished creating the shop. We set the groundwork for the questing system. Added ability created quest objects affected quest objects. I mean, look how much we've already done and we still have a lot to go. So I hope you are enjoying. I hope you're having fun and I hope you're excited as I am, just for the sake of loading some probability uses data. So I'll see you in the next video.
81. Set & Get Float: Welcome back, my fellow game developers. In this video, when we run the game, when we hit the O key, yep, there we go. We are transported to the position that we've saved in our player prefs. So let's not waste any more time, and let's get started. Okay, so now we are saving quest data. The next thing that we need to be able to save as the player's position, as you know, when you walk through your game, Position saved and so is your scene will look into saving scenes later on, or you just can't do it on your own. It's very easy. You just set a string. But let's focus on setting floats and loading them right now, and especially when it comes to the position. So if we look up here and the, and any object we can choose the player because we're focusing on the player. You can see that he has a position on the x, y, and z. And all of those need to be saved in order to load the position properly. So let's do that. But first, we need to find where do we actually want to save this data? And I believe, and it is actually the best place to save data, such as the position is in the game manager. So let's double-click on the Game Manager, open it up and see what we can do in here. So we're going to create a method called save data. So down here under player stat, we're going to create a public void, Save. And we are going to save the data for each position. So we're going to call upon the player prefs dot set float. And why are we using set float not end? Well, obviously because if we look back in Unity and here you can see that the position of the player was 1.91.3. So we need to set the float. And we're going to set the float and we are going to give it a unique key. So it's going to be the player underscore, pause for position and acts. So we're saving first of all, the x. And what should it be called? I mean, what's the value that we want to send it? Well, I'll give you this mini challenge to try and think of it. We'll need access to the player. You will need access to the instance, will need access to the transform on that player. So the transform on that layer. Now finally, we need the axe on that position. So we're accessing the player script, the instance, the transform of the game object, the position on the transform and the x on the position. Okay, great, So now we've set the float for the player's position x, and now we need to issue you a challenge. Then see that one coming. So we're going to finish setting the position y and z. And remember that each axis should have a unique key to it. We're going to create a method to load the data. Why am I saying when you are going to create a method to load the data, you will get the float, get it of the player's position, and load them into the vector 3. And I'll just give you a hint of how you load into vector 3. If you don't want to see it, you do it by yourself. Pause the video right now, go to the challenge. If not said the player's transform equal to new vector 3, x, y, and z, or that. Pause the video right now and go do the Shalon O K back. So we duplicated this line using Control D. I've already explained this. No worries. Hotkeys can take time to understand why. And there you go. So now we're saving the player's position at x, y, and z each have a unique key, just like I told you in here, each axis has a unique key, x, y, and z. Now let's create the load data. So a public void load data. And in here we are going to access the player. The player dot instance dot position, dot instance dot transform. Sorry. So first of all, we access the transform dot position and it's going to be equal to a new vector 3. And we'll open up the brackets. So in here we need to access the player prefs and get the float. And because these are going to be very long lines, we are going to hit an Enter in here, hit the Enter again, and we'll start adding everything here. So first thing, first, player stats, I mean player prefs, dot, get, float. We have to provide it with the correct key. What's that? What happened, sorry for that. So we need to add a comma, and in here we'll need to add the key. And what's the key? It's the player position x. We'll paste it in here. Then we'll duplicate this line again, duplicate it again, and make sure to invalidate term. We need to remove the last comma. So y, z, and that's all between it. To do. So we're going to save all of that. We are going to go into update and create a key to save and load, or two keys to save all of that unload. So and the update. And here we're going to go ahead and check if input and that input again. Get key down. I'm so excited I can push the correct buttons. So keycode will use the I because we were already doing that. And the quest manager and you know what? Because we are already doing it and the cost manager, let me just go copy both of these lines. Base them in here. And I don't recommend the true average copy and paste code. And we're going to load the data. So load the data safety data using R, using all save all of that back in Unity that C doesn't need to compile. Again, we're going to walk over to the waters in here. So there we go. We're going to hit the I key. Data has been saved, go back, date, die right, date. Okay, So anyways now we want to load the data. We hit the O key. Yep, there we go. How cool is that? Our player is being transformed automatically to the other side of the page of the, of the tile map room, whatever you wanna call it, just using keys. So I hope you're enjoying, I hope you're committing all of your changes. Some of you would have looked at this. Oh, my God, I forgot to. I haven't been committing for like seven videos in a row, but this is a good place to start. So I'll see you in the next video where we will be saving our player stats.
82. Saving & Loading Player Stats: Welcome back, my fellow game developers. In this video, when we run our game, notice two things. The stats in here for everything and the healer up here, or you can keep track of it on the hierarchy. When we had the oaky, we are not just the transported to a different place, but we also have the stats that we have this silver acts started the defense, the current HP, the current XP has changed and the healer has disappeared. She is no longer active. So let's not waste any more time. And let's get started with saving and loading player stats. End player perhaps. Oh, sold time to save some player prefs. How are we going to do? The first piece of data that we want to save? Of course will be saving everything gets saved. Data method is the, whether the player or any character with the player stats is actually active and the hierarchy. So we're going to create a for loop. And I equals 0, I goes through the player stats dot length. And we're also going to increase it by one every time and player stats are in here. So there you go. We have an array of players stats already available, so we don't need to actually access it. In any case, we're going to check if the player stats at position i dot gameObject dot active in hierarchy. If it is, then we're going to access the player prefs. We're going to set the integer. And what sort of key do we need to give it? While because they have player stats, that means they are a player underscore, we're going to concatenate it with the name of the player. So that's going to be, sorry for adding that. That's going to be the player stats at position I. That the player name. There we go. So with the player name. And we'll add finally, underscore active. So this will differentiate the player by, first of all, using get the player at the end or at the middle the player name. And finally, we set it as whether it's active or not. So here if it is active in the hierarchy, then it's a one. Save that. And you know what to do and here. So if you want, you can continue on without me. There we go. 0. Save that. Okay, great. Now the next things that we want to do in here is saved various player prefs that we have. So for example, we want to save, let's say the level. So player prefs dot set nth because Lovell's are integers. And we're going to go ahead and use the player and name. Paste it in here. And then we'll concatenate with it something different which we want to represent the levels. So it's level and it's going to be the player stats at position I dot the left. So player level. Great. Now again, we'll duplicate this. It's the player by name, and instead of level we have the current XP. So we're going to save the current x beam. And let me, let me just make this capitalised current XP. And you already know what the player stats are. We're going to save all of them. So I'm going to use the magic of editing to take us to the place where I've finished all of this work. So I'll see you in just a bit. Okay, Welcome back. So I hope you did this mini challenge. As you can see, I've set all of the integers and also the strings you may have come up to this point and face this challenge yourself. So as you can see, we have everything in Max, HP current, HP maxima current manner, dexterity defense, weapon name, armor name and weapon power, armor defense. And I've saved the weapon power and armor defense. Even low. That should be obvious from the weapon that we have equipped. But because maybe at some point you want to add, let's say power-ups to your weapon or maybe, I don't know, go forge it somewhere, increase the weapons power, the armistice defense. Then you can also save in here. Okay, great. Now it's time to load all that data. And again, we are going to have a long list. So what I'm going to do is I'm just going to do the first couple of lines and then I will give you the opportunity to finish for yourself. So first of all, we need to create a loop. So we are going to take this right here, steal it from the safe, paste it in the load data. And let's get started. See what we need to do in here. Okay, So we're checking if the player prefs Get Int and we're using, and let's use, let's copy the key in here. And we'll paste it in here. So we are getting the integer. If it's equal to 0, that means the player isn't active. So player stats at position I, thought game object dot set active to false. Else. We're setting it to true. Okay, so now we can turn on and off the player if he was on and off when we saved the game. So now it's time to load the player stats. So the way we're going to do this is we're going to go to the player stats, will access the position at i dot player. Let's say, There we go. So we can first of all maybe low the name. So name equal to player prefs. So player refs. And we're going to get a string that we save the player. Also we didn't save the name, so layer level dot, get. Sorry for that. And I was thinking at that's why it took me. I was thinking, what, what did we do actually need it? We save the name. Why did we save the name? So maybe we could save the name. Why not? Not? A very bad idea. We're going to paste the key in here, and that's all that we need to do. So I'm going to again use the power of editing, but before I do, I'll teach you this nifty trick. So we'll copy all of that, paste it in here. And basically, all that we need to do is we need to get this, move it to the right at an equal signs or sign and remove these and then get an int. I'm not sure if that's quicker. I think it's quicker. I'll see you in just a bit o k. So I hope it doesn't take you too long. It took me, I don't know. Maybe 30 seconds, one minute, two minutes, and mature anyways, let's save all of that and let's test all of this in Unity. So we'll go back into our game, and now let's go ahead and run our game. Let's move our player somewhere. We are going to give him a bit of experience. So 68, current XP, current month, 33, I'm in current HP 33, current 10, 22, dexterity, let's say it's 45, defense 88. I want to remember these numbers, but I hope that you will. And we are going to equip couple of weapons. So go to Items, use for Jimmy, use for Sarah that golden axe. And if the weapon is working, I'm sure that the farmer is working. And let's see. So as you can see the equipped weapon on the player for the healer, let's see what we'll do. And for the healer, I'm going to turn her off. So I'm going to remove the healer in the hierarchy. So we'll test whether we are saving or not. And finally, we'll hit the icky. So make sure to remember these numbers so we don't cheap. I think we have everything setup for the player. So these numbers are the ones we want to. Number will hit I again to save the data. We'll go back. We'll run the game. So now when we load, we can see that we don't have any equipped weapon or weapon name, neither on the player nor on the healers. So when we hit the O key, there we go, We are transported the equipped weapon as the silver acts with a weapon power with 68 current XP with everything set up and the healer has disappeared, but she still has the colon ax. So as you can see, we are saving the player prefs. Yet there is a small problem. If you've noticed that the equipped weapon, where is it? We cannot find it. So how are we going to store items while items are of type, items manager, they are lists. How are we going to save them? Well, in the next video, we are going to find a very clever way of doing that. So commit your changes, and I'll see you in the next video.
83. Saving Item Lists using Items Assets: Whoa, whoa, whoa, whoa, whoa. I know this is a long video, but whenever you have limited resources, you need to create something very smart to sang, circumvented. So currently, when we run our game, you'll see that when we hit the M key, we go to items. We don't have anything. If I close back the menu, I had the oaky. This means I load the data. You can see that we haven't picked up any of our items. But when we go to the items menu, you can see that we have a lot of items that we can use on Jimmy, on Sarah, and so on. So let's not waste any more time and let's get started. Okay, so now it's time to save our inventory. By inventory, we mean we need to save our items. And how are we going to save our items? Well, we only have the player prefs for the integer, the string, and the float. How are we going to go about saving items, which are complex objects that have many characteristics and let's say different kinds of variable inside of them that we need to save. What we'll do. We're going to be very smart about this. We'll create an item's asset script. And this items as a script will be placed on the Game Manager and it will contain all the possible items that we might have an hour game. Then we'll create a method that using a string goes through these item assets, gets the item, and then adds it to the inventory whenever we load. Do not understand anything, neither did I. Let's get started and see what we can do about this. So first thing, first, creating an item's asset. So we're going to go into the scripts, will go into the where should we put it in the manager level management items manager. That's put it in here. Sure why not? Right-click create C-sharp script. Items. Assets, hit Enter, wait for it to compile, and they now added to the game manager. And let's go ahead. Apply only the assets item so we can apply the changes to the prefab, only the ones we want. We don't want to apply the quest manager also, you know, we can apply all of that, but in the other, managers, on the other game managers will have the same costs. We might not want that. But anyways, let's focus on the task attempts. We open up the asset manager. First of all, we're going to make this a singleton pattern because we don't want it to be replicated anywhere. So public static items, asset, instance, and then start if the instance is different than null, and the instance is different than this, then we are going to destroy this object. And then else, we'll just set the instance equal to this. Okay, So this will make sure that we only have one items, acid, we don't have many of them. Second, we need the items. So we're going to create a serialized field of type items manager. It's going to be an array because we have multiple items and it's going to be called the items available. Labile. Save that. And we're going to create the method will remove the update, I'm sure will not use it, like we say every time and then we use it. We're going to create a method that returns the item manager or the Python script. And it's going to be called get item asset. And it's going to take in a string, which is going to be the item to get name. So it's going to be the item that we want to get using its name. And we're going to use for each. So we'll be looping through all the items available. So item and items available. And if we catch an item, item name is equal to the item to get, then we are going to return the item. And if we finish this entire loop and we don't find the item, as you know, we need to have a return. It's going to return null. Save that. So I know I went through this very fast, but these are very basic things. So we'll save that. We'll go back into Unity. We are going to open up the items available and let's go into the Prefabs items. Go to manager. Let's lock this down, select all of these, drag them into the items and not into the list on the items available. And there you go. We save all of that. We can even apply the changes and now we have all the items, assets available. The next thing is to actually save our items and the game manager dot save data. So it's going to be part of your challenge. And we are going to save our items and I'm going to give you the step-by-step process. So you'll need to set the count of our list of items using the set end. You'll need to loop through all the items and set the items name and the correct order. By correct order, I mean, we're going to go through four loops. We're going to set the string and the key has to be represented by the position I. So at each item. And let me just explain it in a better way. We're going to have each item because we already have the item and name to make it unique, you'll need to set it or represented using the position as we are going through the for loop. And finally, you also need to save the amount of the item that we have. No need to check if it's stackable, make sure that the amount is greater than one and set the integer. So I've given you everything, pause the video right now and go do the challenge. Oh, okay. So how did you get on with that very, very hard challenge in here, we are going to go ahead and call the player prefs. And because already have a lot of coding here, we are going to choose all of the scold. Yep, all, all, all of it. We're going to end except for the position we are going to right-click. We're going to click on the quick actions and refactoring, and we're going to extract this method. So there we go. Now, this is going to be called his having player stats save that. So as you can see now we only have one line to represent saving all the player stats. We can minimize this. We can even do this for the position. So right-click quick actions and refactoring, extract method, Saving, player position, Enter. And then as you can see, we have a very clean method and we're going to do a lot of these quick action and refactoring of methods later on, as you'll see, you can easily do this in the menu manager. So I recommend that you go over especially the player. So as you can see, the player and the update does a lot of things. So this is the perfect place to start refactoring you into methods. So we have a clear update. I never like to keep update like this. I always like to refactor. And whenever you have a lot of code, Like saved data, what does it do? You have to look through all of the code. Now we can clearly see saved data, saves the player position, saves the player stats. Excellent. Back to the task at hand. We're going to go into the player prefs. We are going to set the end. We are going to save the count of the list. So it's going to be the number underscore, underscore items. This is the key and the value is going to be the inventory. Dot instance, dot get item, dot get items, list, dot count. Save that. Next we're going to create the for loop. And it's going to be in the inventory Door instance dot cutlass, dot count. And we're going to add one each time. And in here we are going to first of all get the item and to a variable. So the item is of type item manager, the item in inventory. And it's going to be equal to the inventory dot instance, dot get list at position. So now that we have a reference to it, the next thing to do is to set the player prefs of the string using, let's say we're going to call it items or item underscore. And we'll concatenated with the position. So now it's unique. And finally, we'll add an underscore and make sure that we know it's the item 1, 200, whatever name. And the value is going to be the item in inventory. Item name. There we go. So now we have the item name. And then we are going to check because we need to get the amount. We're going to check if the item in the inventory that is stackable. If it is, whoops, sorry, if it is, then we are going to save it using the player prefs dot set and underscore concatenated with an I. And I hope I'm not moving too fast. Am I moving too fast? If I am, please stop me. Obviously, you can't. But if you want, you can always, always refer to the questions and answers section under the videos. So what are we saving? I forgot all the counts. So the item the item in inventory, the amount that I say count, IMF, amount, grid. So now we are saving, we are first of all checking for the count. We are saving the number of items that we have. We are looping through all the items in the inventory. We are saving the item at each position and to the variable item in inventory, we are saving this name of that item using set string with a unique key and here that is represented by item name and I, again, why are we saving the name? Because the items assets, we've created a method that gets an item asset using the name. So this will be used later on when we load. And finally, where are we? Okay, so, and finally we are checking if it's stackable and we are saving the amount that we have in order to also load it. Now, the next obvious step is to also load that data. So let's make this a bit cleaner. So we're going to refactor this extracting method and it's going to be called loading player position. These all are loading the player stats. So Extract Method. And now we are going to start, let me just minima, okay? And now you can see clearly what do we do in load data? We are loading player position, loading player stats. It's very clean. It's very nice. Let's load our items. How are we going to do that? We're going to first of all, create a looping. A loop. If you want, you can pause the video right now and try to load the items yourself. I do recommend it. It's very important for you to try this yourself. So pause the video right now, go to the challenge player prefs dot getInt. And you can actually start doing this at any point that you want. So let me just get the number of items. This is very crucial that you don't mess up. The key. Paste it in here, dot count. And I didn't even, Sorry for that. We need to make sure that I is less than this and we're increasing it. I plus, plus. Okay, great. Now we are going to create a variable which is going to be the item name, and it's going to be equal to the player prefs, the get string. And we're going to use item underscore, copy this, paste it in here, and there we go. Save that. So now that we have the item's name, we are going to create the item. So the item manager is going to be the item to add. It's going to be equal to the items Assets dot instance, dot get item asset using the item name. Save that. And we'll also create a variable for the item amount and we'll set it to 0. 0. Great, So what are we doing in here? We are loading the player prefs, get int, the number of items. We are using it to loop through the foreach. And at every position we are, first of all, getting the name. After getting the name, we are getting the asset and then we're getting the amount, and then we're checking the player prefs dot has a key which is V amount and this should have been amount not name. Sorry for that. We're going to copy the ski in here, paste it in here. So if it does, then the item amount is equal to the player prefs. This is the same exact thing except for husky. We get the int. And we closed self, save that. Okay, so now we are also getting the amount at me, separate these and said this. And finally, finally, we need to add these items to the inventory. So inventory, for instance, thought at items. And we add the item to add. And not only that, we need to also check if the item to add as stackable and where is it and the item amount is greater than one, then we are going to get the item to add dollar amount and it's going to be equal to the item amount. Save that. So what are the final steps after we've created the item amount, we checked if it actually has an amount by checking the key. If it has, then we're going to set the item amount to the item amount and we're going to go into the inventory, will add the item to add. We're going to check if it's stackable. If it is, then we'll check if it has an amount greater than one. If it does, then the item dot amount is equal to the item amount. So let's save that and let's see if any of this works and our gain, something is wrong. And it's telling me I've missed. What did I miss? What this is is the savings player. Oops, What is this? Should ideally, it, should I not delete it? Let's delete it and see what happens. I'm not sure what this was. Hopefully. No, I don't I don't think so. Let me just check again. So we have no pie. Think No, there is nothing wrong. Hopefully, if there is, then we'll know, save that. Go back into Unity. Nothing wrong anymore. Run our game, hit the, where is it? Let's see what items we have. So items currently we don't have anything. So when we pick up these items, There we go. We've picked up these items. Items. Here we go. These are our items we are going to hit I, so has been saved. Excellent. We'll stop running the game. We're going to run the game again. We check for the items. We don't have anything. We exit, we hit the O key. There we go. So now we can see that the data has been loaded. We didn't pick up any items, right? All of the items are here. I'm items. How cool is that? So even though we cannot save items using player prefs, we've created a very, very smart way, circumventing that and actually saving our items using the items asked. How cool is that? I'm so happy that that worked. It's an amazing way of saving different kinds of data with minimal. And even though you might think that player prefs is very simple and limited, but as you saw, we can use it for a lot of things. So I hope you enjoyed this video. I hope you are enjoying the course. I hope you'd like an instructor. If you do you know the drill, please go review the course. It could mean a lot to me. It would help me a lot with Procreate, messing with the course. People will see that it's a good course. It will go in there. It will benefit from what I'm teaching and that will help me out a lot. Thank you so much. I'll see you in the next video. Don't forget to commit your changes.
84. Section 12: Audio In Unity: Welcome back, My favorite game developers. In this video, we are delving into audio. What, how to add an audio source? What's an audio listener? The many, many background music and sound effects that we've added. So now when we run our game, I know you can't hear anything, but if we press the F key, there we go so we can hear the sound of discarding buttons. And as you go through to the end, make sure that you ignore everything under music because it's too much information that we really don't need to commit the changes to. So, so I mean, we can ignore it, but until you get there, let's not waste any more time and let's get started. Oh, okay, welcome back. So now we want to add a bit of flavor to our game, and we do that by adding audio. So audio is a very central part when it comes to games and especially RPGs. So how are we going to add music? First of all, we need to understand what all your needs in order to be available. It needs a source. So you need some kind of bird, for example, a source. And then you'll need a listener, which is sometimes you. So where all the listeners and the sources. First of all, let's talk about the listener. So the listener is on the main camera. You may have noticed that while digging through the camera components and so on, you'll notice that we have an audio listener. And if we go out from 2D, I've collected to the button in here, you'll see that we have the audio listener right here on the camera. Zoom out. We can make the camera but bigger. Unfortunately, we can see the extent of the listener, but the listener is on the camera and it's where we listened to any kind of sound or music that appears, by the way, maybe you haven't noticed, but it's very cool to look at our 2D game from this perspective and the way funds over. Now it's time to think about how we are going to add 0, 2. So I've provided you with a couple of songs in here. You'll see that I've provided you a file for the music and a file for the sound effects. So we're going to create a new folder in the assets. And it's going to be called the audio. Let's double-click in here and let's drag the music and sound effects and here. So as you know, you can add your own sound effects and music from open game art. Everything that I'm using in here is from there. So I recommend you take the time, go look for some music, some sound effects, add your own what you want your game to feel like, to sound like too. What type of objects you want to interact with that make a sound. Maybe you want to make a pumping sound. Every time your player collides with something, it's your choice, go at it. So we can see in here that we have several music for the path, the dark. Some of them will be for the boss fights for the town theme. And we have also sound effects in here. So for example, we have the discard item, the fire fact monster, and maybe we'll add some later on as we move through the course. But for now, let's add an audio source. How do we add that? Well, we can simply drag, for example, the talent theme into the hierarchy. And you can notice in here the counting now as a component or has a component which is the audio source where we can change the volume, the pitch, the 3D sound settings, although we're in a 2D game, will not use it. And we also have options in here to mute by pass effect, bypass listener effects, so on and so forth. And one of them is turned on. And the two most important ones are the loop where when the song ends, we loop again and it starts again. Or we can play on awake, which will play the sound as soon as the scene loads. So if we now run our game, I hope you can hear through the microphone, but there is sound coming out of the game and we can adjust the volume and turn it off. Now if we turn the play on awake off, we run the game. There you go. There is no sound to be heard. Now. Everything is working. You might say, okay, well, great, in the town, we'll add the town theme. Very good, but there is a slight problem. How do we stop it? Well, do we go every time into the scene? Okay. How does a player who's playing our game, who doesn't have access to the objects in the hierarchy? Well, in that case we will need an old your manager. So let's delete the town theme in here. Remove it. And we are going to go into our scripts. We are going to create, or we can create actually, and the managers will create a new C-sharp script, which is going to be the Audio Manager. Hit Enter will also create an empty game object and the hierarchy, which is going to be the Audio Manager. And we can separate it by space. We can reset the position to be at 00. You don't have to do that. I like to do that. And we're going to drag the audio manager and to the audio manager. In here will also create two empty game objects, which are going to be the music and the sound effects, or the effects for short. And then we're going to go into the Audio folder. We'll drag all of these except for the links. The way I chose all of them. I clicked on the first, held down shift, clicked on the last, and to remove the link, hold down Control, click on this one. That's all you need to do. Drag them into the hierarchy. This will create an audio source for each of the music's, music's, whatever you wanna call them and make sure to turn off the play on awake unless you want your ear drums to burst. So we'll drag them into the music and we'll do the same for the sound effects. I'm not sure what this desktop is. Well, drag them and here we'll turn off the play on awake and we'll drag them as children of the sound effect. So now we will save this when we run our game. There we go. We don't hear anything unless we turn one of them on, but we don't want it to happen on its own. We want to make it happen through our script. So let's go ahead and open up the script and start coding how k. So what do we need? And here, first of all, we'll need a reference to all of them. So we'll create two serialized fields, will create a audio source array to hold all of our music or the artifacts and all of our music. So all of these will be audio sources and I'll call it for extra reference, the background music. So this way we will know it's not just music, it's the background music. Next, we'll create an instance of this object. So we'll go into public, static, or your manager, or your manager instance. And this instance is going to be equal to this. Save that. And we don't want to destroy this object on load. Later on, we might need to make sure that this is a singleton pattern because we don't want any duplicates, not have many sounds at the same time. Let's for now, just focus on Create. And now we're going to create a method that's going to play a certain sound effect based on a parameter that we send it, which is going to be an integer. Before we do that, let's go in here. In the Audio Manager, we should have two lists. So we'll drag will first of all, lockdown. The Audio Manager will drag the music and the background music. And we'll drag the sound effects and to the sound effects. We will save that. And I'm going to issue you a challenge. So I was so eager that collect all of them now, create a method that takes an integer argument as to what song it should play. Use that argument to play the sound effect. Of course, accessing the array using the parameter that we've accessed. And make sure that the input is never outside the bounds of the sound effect array. So let's say currently we have nine. So there we go. We have nine options. So we don't want an input of, let's say 100 and it's not available and sound effects. So this will be a solution or a problem that she will need to find a solution to. So pause the video right now and go do the challenge. Okay, welcome back. How did you get all that? I know I haven't taught you how to play songs, but at this point in the course, I think you already have the ability to go and become a problem-solver on your own. So I hope you don't feel cheated. I've just left you. So we're going to create a public void, play as effects. And it's going to take in an integer parameter so the sound to play. And because we don't want it to be outside the bounds, we're going to check if the sound to play is less than the ASA facts dot length. Then in here we're going to access the suffix array at the position sound to play that play. So it's pretty easy. I don't think many of you were stumbled if you were and not sure how to play a sound, you could have gone into the Unity documentation, which I hope you did. I hope you didn't just stare at the screen, we think for me to do everything. So with that done, we're going to save that. We also need an update to test this out. So we're going to check if we get an input dot, get key down, that get key down. Keycode, what should we use? I think the f hasn't been used for anything. Or maybe the P anyways, let's keep it at F. And we're going to play the sound effect at position. Let's see what position do we want to play. So from 0, if we want three discard item, sure, let's discard an item, save that, go back into Unity. Run our game, hit the F key. Let me increase the sound. Maybe you can hear that. So as you can see, this is the weeds discard sound, but at least we have indication of what's happening. So I hope you enjoyed this video. I recommend that before you go to the next one, That's our test out everything. Try to play music on awake, trying to turn off the music and awake. In the next video, we will be delving deeper into how we can play the music and stop it and use different ones in different scenes. So I'll see you then.
85. Playing Music: Oh, hey, welcome back, my fellow game developers in this video, when we run our game, if we hit the F key, There you go. You can hear the music playing in the background. So in this video, we'll learn how to play music and more importantly, how we can avoid several songs interfering with each other. So let's not waste any more time, and let's get started. Okay, so now we can play sound effects. It's time to play some background music. So we'll open up our script in here. We'll scroll down and we're going to create a method to play the background music. So void, play background music. And it's also going to take in a parameter which is going to be the music to play. What is this? Okay, what are we going to do in here? Well, as we did in the sound effect, we're going to check if the music to play is less than the background music dot length. And we're going to simply access the background music at the position music to play, adopt play. Okay, so you might be thinking, well, great, Let's go ahead and test this out in our game. But you need to realize something. What if we want to play a different sound? Well, what happens? Then? You'll have to sounds on top of each other. One playing sound effects. This is not a problem because sound effects are very short. Rarely do you have a very long sound effect. So you saw how when we play the discard button, it's 1 second tense. And if we have, for example, we discard two items at the same time. Or let's say for example, we don't know, pick up an item and discarded item at the same time, it won't be as bad. But if we start playing one song while the first one hasn't stopped, That's going to be a big problem. So before we actually play any music, we first need to stop music. And this is a method that shoe are going to create. So please do stop the music if you know what the reference was. If you don't create a method that stops all the music, you'll need to research how you can do that in Unity dogs, I've added this because I didn't value in the last video and use the or a foreach loop to loop through all the music and stop all of them because we're not sure which one is currently playing. So pause the video right now and go create that method. Oh, okay, welcome back. So in here we're going to create the, stop the music. If we click on here, we can generate the method immediately. There we go. How cool is that? We've saved about 23 seconds. That's great. Time is money. So for each audio source, because we're going through a song in the background in music. And it's of type audio source. And in here we're going to get the song and we're going to stop it. So that's very obvious. We don't want it to play. And now whenever we want to play a song, any song, we stopped the one that is already there, and then we move on. So let's test this out. Oh, I meant in here, if we get an input and we get the get key down or you know what? Let's just test it out. And here. Play background music. Which one should we play? The last one at five because it's the counting and we're in the town, aren't we? So five, save that back in Unity. Wait for it to compile, run our game. What was the button? Was it I said the I hope that saves the game. What was it? F Okay. Sorry. So there we go. And every time I press Enter, you'll notice that it stops and plays again. Let's try something. Let's comment this out and see what happens. So now if we run our game, we had the F key. Let's try to hit it again. Let me turn down the sound a bit. Hit it again. Well, because it's the same song, it's obviously stopping. So let's say we want to play the, play background music at position. Let's say to save that back in our game, run the game, hit the F. So you can hear that we have two songs on top of each other. So a free stop the music. We should hear only one single music playing, one single song playing. I'm not sure if you can even hear it. There we go. We only have the Battle Music plane because we stop all the other sounds. So now we have protected ourselves against multiple background to music's playing together. So I hope you enjoy it. I hope you are committing all of your changes and I'll see you in the next video.
86. Playing Audio From Code: Welcome back, my fellow game developers. In this video, we are going to be adding sound effects. We are going to add transitional music. So now when we pick up items, it's going to be very faint. Hope you're hearing. There we go, so we can hear a sound when we pick up an item. If we hit the M key, go to items. If we use one of the items on Jimmy, There we go. You can hear it. If we discard one of the items. There we go, you can also hear it. Let's close down the menu and we have hit the close button work even though it's one line of code. When we go to the next scene. There we go, you can hear the music change and to a very nice melody that reminds me of which are three, if you've ever played that game, It's amazing. So with that said, let's not waste any more time and let's get started. Okay, so now it's time to take our audio playing to the next level. We don't want to have to press a button to start music playing. We want it to happen automatically on each level. But the question is, where should we say choose what music to play on the Lovell? Well, I've thought about there are many ways of doing this, but I believe that one of the best ways is on the main menu on the camera controller theater it is. So on the camera controller, each level has its own camera controller, maybe not on the shop. We can change that. We'll see what we can do. But I believe this is a perfect place to add. So in here we are going to create a serialized field, which is going to be an integer. And it's going to be the music to play. So we'll know which music we need to play, will choose it in here. And we will also create a private boolean, which was going to check if a music is already playing. And this is just for an extra step of precautionary. So an update, we're going to check if there is music already playing. Then we are going to set first of all, the music already playing to true. Why are we doing this? Well, because it's an update. We are looking through this each and every frame. So what we're going to do is we'll set it to true, so we only enter it once. And then we are going to get the audio manager. So we already have an instance of it. So we're going to go audio manager, dot instance, dot, play background music and is going to be the music to play. There we go. So we're going to save that. We're going to prefab our audio manager. So an prefabs, that's Prefab the AudioManager. Okay, great, So we'll save that in the virtual camera. And here we are going to watch music. Should we play? If we go to the audio manager music, what do we have in the Audio Manager and down theme? So it's the 5, end here. Five, save that. Let's go to the next level. Where is it? So scenes, mountains. Mountains. Mountains to yep, there we go. Mountains to add in here we'll add let's see, do we have the virtual camera? Yep, we have. And the canvas has been updated. Of course we have the short menu in here that doesn't turn on. Maybe we need to add other things like, for example, the game manager. So let's go into the Prefabs. Game Manager. Where is it? Okay, audio manager. There we go. So now we can play sounds in here. And which one should we choose? We have, I think I've chosen one, heroic demise path of the lake. You can even listen to it so we can double-click to open it up and listen to it. I think it's a really good song, reminds me of The Witcher 3. It's very nice. Even vibe to it. If you want a few vibe to music. I don't know. So anyways, that's the where is it? I got distracted. Element three. Scroll down element 3, save that. And you don't want to overwrite this, we don't want to override the cameras. That's it. That's all that we need to do. Because if we override it, so if we apply the changes and here and the camera override it, we apply the camera. All of the other levels will have the same music to play. And I've just noticed that play is wrong, but we don't want that. So keep that in mind. We don't want to have the same music playing on each level. So let's go back to the town. So where is it the scenes? Down to save that? Let's run the game. The game. There you go. You can see that the music is playing. If we walk to the next. Okay, So obviously there's something wrong. There's some music playing already in the background. So we'll need to fix that. And the problem in here is that when we run our game, It's not that we have anything wrong with the code. It's just that when we go to the next level, don't destroy the old your manager. And yet we have an old your manager in here. So if you remember in the first video in this section, I said that we need to make this a singleton pattern. So to do that, we're going to open up the layer. So the player was a singleton pattern will just copy this. We're going to put it in the Audio Manager. And this should fix everything because our code is correct. So we go back, we run our game. We walk towards the edge. Yep, there we go. So we can see that we change our music. But unfortunately we still haven't fixed the problem that our cameras, and here in the virtual camera, you can see that it doesn't follow anybody. Where is it in the virtual camera? So the follow is missing. We aren't following the player. I know it's a bit frustrating. We haven't gotten to the while loops, but don't worry about it. We'll fix this in Jew time. So I hope you enjoyed. Before we go, we need to do one more thing, and that is a challenge. So play sound effects when we discard the item, when we pick up an item, and if you have other sounds you want to add. Also apply those. I'm just going to apply the first two for now. So pause the video right now and go do the challenge. O K. Welcome back. So in AudioManager in here you can see that we have the play sound effect and we choose which sound effect we want to play. So if we go to the, the the menu manager somewhere in here. So Menu manager no, As it in here, No. Apparently we need to open it up from the Canvas. So Menu manager, let's double-click on the script. I'm not sure whether 12th. So when we want to use some kind of button or discarded. So there we go, discard item in here when we press it, so we update the inventory and then we access the Audio Manager. For instance, play sound effect. And which one should we be playing? If we open the unity, we go to the audio manager. It's the US or the scored item. There we go. Element three. Open it up and here at 3, save that. And now when we use the item in here, or because we are already discarding the item, I'm not sure this is the best idea to do it in here. So the way we've set it up, we are discarding the item. So we are playing the sound effect in here. Not a very good idea, but in any case, we'll just play the sound effect. So we'll copy this, paste it in here. What does the sound effect to use the item, its own element 8. And there we go, play sound effect element 8. As you can see, we've put in here that this should be moved. So because of the way we are setting up our old you now will have to copy this line in here. And we're going to paste it in here. So we don't want to hear the sound effect of the discard item. We'll save that. If you want to really save up some code, we can actually go ahead and quick action and refactoring and create a method just for these two lines and then call these methods in here. I don't think that's very necessary, but it's, of course better practice. It's very ugly and not very professional when you really see these two lines in here. But no worries about that. We're going to save, we're going to just test this out for our game. We're going to run the code. And we could have added also maybe for the item pick-up put have been a good idea. Let's pick up a couple of items. For items, click discard. There we go. I'm not sure if you heard it. It's a bit faint. So now we're going to use this on Jimmy. There we go. It's a very small sound, but that's all you need when it comes to sound effects, especially with the music and the background. So great with that done, I've stopped again. Let us also add when we pick up an item. So where do we handle the item pick-up? Is it on the where is it? Where is it the IT manager? Is it in here? Yep. There we go. So when we add the item, we're going to play the sound effect. So AudioManager, dot instance, dot, play as effects. And which one picks up the item. Element five. There we go, Save that. And the only thing that I'm worried about is that when we pick up an item at gets destroyed and hopefully the sound fact, we'll have time to play. So or it might not matter. We are going to run our game. So you can hear the sound. There we go. Excellent. So I hope you're enjoying. I hope you had fun adding music to our game. You can see that it adds a lot more, let's say, dynamic field to the game. So if you're enjoying the course, if you're like me as an instructor, even though I may couple of mistakes sometimes, no worries. I like to keep them just for you to understand the process of creating because nobody's perfect. And even though I've prepare the scores, so I've prepared this game already. Big shocker. I do sometimes make mistakes and I want you to understand this because the process isn't easy. You're not just going to, no matter how many hours you have, no matter how many years of experience, you'll always come up to something and be like, why is this not working? How do I fix it? You'll need to use debugs a lot. So just wanted to be as authentic as possible. With that said, if you have the time, leave me a review and I'll see you in the next video.
87. Section 13: Main Menu UI: Welcome back, my fellow game developers. In this video, we are creating or laying out our main menu. So do you like it? I think it looks kind of good. So legends of conquest and big red, bold medieval font. And we have three buttons to continue to start a new game and to exit from our game. So obviously they don't do anything, nothing does anything currently. I think it looks good. I like it. I hope you like it. I hope you find your own resources. So let's not waste any more time. And let's get started. Oh, so time for a main menu. Let's go ahead into the file, create a new scene. And we're going to make sure that it's 2D. And in here we're going to save it to the scenes. And then we'll call it the main menu. There we go. Save that. Oh, okay. Now the next thing is we're going to right-click and add a canvas. Or we can immediately just go ahead and add an image. And this will add a canvas automatically. And we're going to go to the Canvas and make sure that the canvas scaler. And here is the constant physical Nope, scale with screen size. And we're going to make sure that it's 1920 by 1080. Hit enter. Okay, there we go. Now the image, what are we going to do about the image that's going into the sprites? Let's right-click and create a new folder, call it the background images at Enter. And I've provided you with a couple of images now I do recommend that shoe. Go find your own because mine are in that good. As I've said Always, I keep telling you don't do the same as I do. Go find your own. And I'm going to click on the image. And let's see, Let's drag this one. And let's set to native size. And let's move the image right down to the center. So there you go. I think this is a good image. Maybe, maybe not, maybe you hate it. That's okay. Everyone got their opinion. So we're going to go ahead and add a couple of things in here. Now, what does a main menu have? Well, mainly it has three things. First, it has the continue, the new game, The quit, and the options. So let's go ahead and do all of that. So first thing first is we're going to see what to add in here now, options, I'm not sure that it's important to have options. We'll just add a virtual options just to see how we can go from one screen to the next and so on. So let's go ahead and add a couple of buttons in here. So we'll go to you, I will add a button. So this button, of course, we're going to go to our sprites. And we're okay, so materials, UI elements, we're going to add this to our button Sprite. And we're going to remove the text, add a text Mesh Pro. And of course it's going to be the medieval and it's going to be Continue. There we go, continue. And let's make that button a bit bigger. So we're going to make this button a bit bigger. We're going to know what that background really doesn't look good. I just noticed. Well, we'll change it later on. So this is going to be the Continue button and in the text Mesh Pro are going to make it completely black. There we go. We're going to make it bold. We're going to put it in the correct position just a little bit. And let's position it in the middle. Increase the size again. Continue. There we go. So continue. And I don't think we'll add anything else. We'll just need a second button. And I think this button is actually too big maybe. Again. So this one will be the exit. This will be the, so the Exit button. Exit. New game. And we continue. Okay, so I guess that's pretty much all that we need to create. We can create options if you want to add. And I'm going to change this background because I really didn't like it. So background, let's add the cold. Oh, that looks much better. Okay, great. So the exit, the continue Ultra to set that we can use a background layout or a grid layout to make sure that all of them are perfectly aligned. I don't think we'll need that for now. And we're going to go ahead and add a text Mesh proton here, a big one. And this is going to be the gain title. Title and we're going to call it the legends of conquest. Conquest will make it bold, will make in the middle, in the middle. And completely black was the color. Okay, there we go, the color. Let's go ahead and add a bit of color and make sure that its medieval party. I'm not sure what it's called that. But anyways, whereas this okay, so there we go. It's going to be about this big. Maybe we should change the color. We'll see in just a bit. Let's increase the size. So legends of conquest, and let's see what we can make of this. Oh, yeah, So I think red is a good color. That's the white. What also is not about color, but I think I read completely read as much butter. And nope, I think let's expand it even more and make it even bigger. Yeah, we can even call it legends of conquest to, that's the second one that we've created. But anyways, legends of conquest, That's good enough. I think this background suits the feeling of the game. It depends on the feeling of the game. So as your game a bit dark, I think mine will be because we have a demon roaming around. If you want your game to feel more. Let's say peaceful. You can use the piece. If it's more of an adventure, you can use the piece. And you can also find your own backgrounds, open game art or any kind of background to that matter. Okay, let's see. We can add a lot of stuff in here, maybe the underlay, we can change it. Let's see if we make it white. Does anything affect our Actually it looks worse. Let's just keep it at that. We'll save that. Great. So now we have three buttons and now it's time for a small challenge. And that challenge is to set your own main menu. Set up your own main menu using your font and background, et cetera. And have fun with it. Take your time. So the main menu is the first thing is that a player sees you need to make an impact in this position. So I recommend that you remember a couple of games you've had, looked through them, see how they operate and what you can do. So pause the video right now and go do the challenge, commit your changes, and I'll see you in the next video.
88. Main Menu Manager: Welcome back, my fellow game developers. In this video, we've actually added functionalities to our button, but as you can see, we removed the Continue button. We don't no longer needed anymore. So when we run our game, There you go. Well, oh my God, a Continue button has appeared. Well, that's because we actually have some kind of keys indeed player prefs that we can load our game. So when we hit the continue, it doesn't do anything. Liquid gain tells us that we just did. If we had the new game, we start a new game. How convenient? So let's not waste any more time and let's get started. Okay, so now it's time to give functionalities to our buttons and unfeeling to tar today. So I'm just going to give you the challenge. Create a main manuscript. So create the main menu script and attach it to the main menu canvas. Create a variable that keeps track of the Continue button. I'll tell you why in just a bit. And one for the new game scene. Because you know, when we start a new game, we need to go to some new game scene. And then we'll need to create two methods for the new game button and the Exit button. Finally, new game should take us to the new GameScene and exits should simply print out something. So pause the video right now and go do the challenge. Oh, okay, come back. How did you get all of that? So in our scripts will go into scripts will go into where should we save IT? Managers. Yeah, sure why not In the managers will right-click, create a C-sharp script and it's going to be called the main menu. Hit Enter. Wait for it to compile this as the new game button. So new game button, or moving here, let's go to the Canvas. Let's call this the main menu canvas. And we'll add the main menu to the main menu Canvas. And we're going to, okay, So we've added the wrong, we've added menu manager, Remove Component, main menu. Okay, great. Let's close all of this down and let's open up our men, men. So in here, what are we going to do? Well, we said that we need to references. The first one is a serialized field of type string, and it's going to be the new game scene that we are going to go to. And then we'll create a nother, serialized field which is going to be of type game object and it's going to reference the Continue button. Why are we doing this? Well, obviously, because if we've never created or if we've never played this game and we can't continue, then obviously we shouldn't see the Continue button. We should only see the new game and the exit. So the next step is to go ahead and create a method for the new game button. So public void new game button. And here we are going to access the scene manager. But before we do that, we'll need to access the scene management. Or before we even do that, we need to access Unity engine then the scene management, very good. Scene manager dot a load scene and we'll simply pass there the new game scene that we want. There we go. And then we'll need to create a method for the exit button. So public void Exit button. And then here will simply print out in the debug log know, just log error. We just quit the game. So we just quit the game with a couple of exclamation marks just to make sure that this is something weird. Okay, so next thing we need to do is we need to make sure that we turn off the Continue button whenever it is not needed. So and start as soon as we open the main menu, we are going to check if we have any key in the player prefs. So if we do, for example, have the position of the player on x, that means that we've previously saved our game. So that means that the Continue button can be activated. So in start, as soon as we start, what access the player prefs will check if we have or has some key, and we'll go into the game manager. There we go. When we save the player stats, which ones should we choose? I think the best option to choose is in here, the position. So it's the easiest copy that we'll paste it in here. So if it has good, this returns true. That means the Continue button that said active as true. Else, if we don't have anything, then the Continue button, active false. Now there is no way of testing this because we've already saved multiple times. How can we make sure we can actually turn the Continue button off? So we're going to turn it off and then we'll see if it actually works. So in the main menu canvas we have the Continue button, which is this one, and the new game scene, which is going to be the town, Let's say the town to copy that. Paste it in here, save that, okay, and before we do that also, we need to go to the button. So the Continue button for now doesn't do anything we're going to add. So remember how many times I forgot to do that previously. Now we are moving along. So you see, we can always learn from our mistakes and new game. For the exit. We're going to add an event onclick at the main menu. Go to main menu exit button, save that, run the game. There we go. We have the Continue button, even though we turned it off, if we click on the exit, you can see right here the console prints out with just with the game continue, doesn't do anything. But if we click on the new game and there you go, How cool is that? So everything is working perfectly fine. There is just one thing which is the loading. In the next video, we'll actually start loading our game by creating a separate scene for the loading, which is going to be very exciting. So I'll see you in the next video.
89. Continuing The Game: Welcome back, my fellow game developers. In this video, when we run our game, when we hit the continue, we appear in our game. And if we hit the M key, we go to the items. We can see that we have the items even though we haven't picked up anything, we have loaded them. And if you can't hear any music, that's because I've muted the audio so you can hear me clearly and we don't have to shout over the sound. So let's not waste any more time and let's get started with loading our game. Oh, okay, so time to actually use our Continue button. How are we going to do that? Well, the Continue button is essentially a loading mechanism. So there are multiple ways that we can load a game, but one of the best is to actually create a separate scene for the loading of our gain as that of adding everything in our main menu. So, and let's go and to new or create a new scene. We'll create this. We are going to save this into the scenes and we'll call this the loading scene. There we go, save that. Before we forget, let's go to the Build Settings and let's add the where is it? The loading scene and the main menu. There we go. So inside of the build settings, okay, great, save that. Now what are we going to do in here? Well, there are a couple of things that we need to add. So first of all, we'll need to add, the player will need to add the Audio Manager. We won't actually see all of this. This will be seamlessly transitioning through the loading scene. We'll add a game manager. Finally, we also need the UI canvas. Whereas the UI canvas, I cannot see the UI canvas. Okay, So there you go. Via Canvas. For some reason, I couldn't see it. No worries about that. Now we have everything set. The next thing to do is we're going to create a game object in here. There's going to be called the or no, simply the loader. It anther. Let's reset its position. Double-click on it. And we are going to go ahead and create a separate script. Where should we created maybe level management or managers, Let's created inside of mantras. I feel that the managers, I like the trash, everything that we don't need or not sure where to put it inside of the managers. So loading the scene or scenes should have been called Scenes. No worries about that loading scene. We're going to add it to the loader and we're going to open it up. So the first thing we want is to actually have a weight for time to load. Don't want the loading to be instantaneous. We just want a couple of seconds before we load. So, and here we're going to create a serialized field where we can determine how long we want to wait. So float, way to load, fine. Okay, Great. Now the next thing to do is we want to load the correct scene that we're in. But if I can remember, if we go to the game manager, saved data. Yup, in the safe player positions, safe player stats. But we didn't save the scene that we are in anywhere. And it's going to be part of your challenge. So your challenge is to go to the game manager and set the current scene and the save data method in our co-routine yield. Did I not say that we wanted to create a coroutine? Oh yeah, I did. I've said that we are going to wait to load in our coroutine, yield the time using the variable we've created. Access the game manager and load the data, access the quests, and load the quests 2. So pause the video right now and go do this kind of big challenge. Okay, welcome back. So in our game manager and here, and I'll just keep it in the saved data and words about that. So player prefs, dot set, and what are we working in? Okay, so set string, we are creating the current underscore scene. That's it. I think that's enough of a key. And then we're access the scene manager. And this is the tricky part. So if we access the scene, okay, so we can't use the manager in here. So Unity engine dot scene management, save that case. So back in here, scene manager dot. And how are we going to, okay though, there are this, we are going to get the current active scene. And we are going to get the name because we are setting a string. We'll save that now back in our loading scene. And in here we are going to go ahead and access the public eye enumerator and load scene, we're going to call it. And in here we're going to immediately yield return. And new way. For seconds. Wait four seconds. Where the time to wait, time or time to load? Wait to load time. And what are we going to do in here? Well, first of all, we're going to load the scene. So Scene Manager, we don't have it, will need to add IT. Manager dot load scene. And we're going to access the player prefs dot GetString. And we're going to get the where is the GameManager seen copy that, paste it in here. Close this off, save that. Now we're going to access the game manager dot instance dot load data. And the quest manager dot instance dot load quest data. There we go. That's all that we need to do. But for finally, we are going to check if we actually have any wait for loading time and then call the coating. So if the wait to load time is greater than one or greater than 0, then we are going to start a co-routine which is going to be the load scene, and that's it. Save all of that. And finally, we'll need to go into the main menu, the popular vote Continue button. And in here we are going to call this scene manager dot lot scene. And we can either actually name this and here the load seen copy it from our game or we can, as we did previously, create a string in here. But for now let's just copy the load scenes or scenes, the loading scene, copy that, paste it in here. Save that saved loading because I've copied it from him. No worries about that. We're going to save this one. Also go to File Build Settings and we're going to add also, we've already added the loading scene and the main menu. Okay, save that. And now let's whereas the main menu, there we go, MainMenu. Let's open up the buttons. The continue. I'll click jaggedy Main Menu canvas, go to main menu, Continue button, save that, run the game. One more thing, I think this will give us an error because we haven't actually saved a game where we have the currency. So if we click Continue, we'll open the load. And nothing happens. Because in our loading, if we go to the loader, the wait time to load as 0, we're never calling it. So again, let's try this one more time even though I'm sure there's going to be some kind of error. Continue. Okay, so there we go. We have an error because we don't have a current scene. So we'll need to go to the stop this, go down to run our game. Data hasn't been saved. Exit Main Menu. Run our game. Continue. Yeah, there we go. But for some reason we don't have a player where z. Whereas our player okay. As his appear, Can we move? Yep, we can. But because we still haven't implemented that, we've just done this down. I'm going to mute the audio because we didn't yet implement the follow cam finding our player. That's why we can find them. But as you can see, we have all of our items. If we hit the M items, yep, there we go. Oh, this because we picked it up. Did we save any items? I'm not sure. Okay. But we are loading data. We know that the game manager data works. So no, actually if we go back into the town and we run our game, there is a slight problem. So if we pick up a couple of items, we had the key to save data, we exit, we run. We should see right now if we, oh, I'm items. There we go. We have the items, we have multiple items. But if we go right now to the main menu, run our game, and click on Continue. We have to fix this problem where we actually see the player. We don't want this to happen, we want to keep it. Okay, so now if we hit the M key, go to items or no. Okay, So the items are correctly loading. That's good. So that was just a bit of a debugger in my mind. The final thing that we need to fix and the loading we need to actually make sure that we don't see the player or any of this. We can actually go to the main camera and change this to completely black and remove the player. This is one way. So there we go. We put them outside, we save that, go to main menu, run the game, continue. Wives are player in the middle, no worries about that. For some reason the player goes to the middle. We'll just move our camera up here, save that. Back in main menu. Run the game. Continue. We don't see the player. Great. And then we paid into our game. Can we move? We can do we have an items? Yep. There we go. We have everything and that's it. That's our loading mechanism. So I hope you enjoy it. And if you went too excited about what was going on in the last couple of sections, I know that it's not the most exciting thing to do, but it's very crucial to have good UI, especially when it comes to RPG games, because we are going to be staying along time in UI and having menus and so on and so forth. And the next section we are actually going to start with our battle system, which is the core of our gameplay. So I'll see you then.
90. Section 14: Creating A Battle Arena: Welcome back my fellow game developers to a brand new video and a brand new section, and a very, very exciting section. So as you can see, I've created a world and here with some lava using sprites that I have left to in the resources, you also can go into open game off. That's actually where I got my resources. You can see in the whereas the file, the tiles, the dungeon, so it's under the name cave just gave. You can find whatever you want. So when we run our game, now what let me maximize everything and turn up the volume so you can hear the creepy music in the background. So run the game. Yep, there we go. So we walk around this damp cave with those holes in it. So in here we're going to have our battles with some monsters. We have some lava in inhumane need to fix this right here because we can pass through and we have these cliffs in here now our wings clipped through, That's a bit of a problem, but no worries about that. We can also walk in here. This is where the boss battle will be fought. In here, Gollum wants to throw the ring or no, no. Column wants to keep the rain, but Frodo wants to throw the ring, but he also doesn't. So we'll see what happens there. And in here we can walk around. We can also fight some battles in here. So maybe easy battles in here. This is the entrance of the cave, so we always need an interests. So how did your monster get here, or your character? How did you get here through the door? It's very important to not break immersion. And let's see and hear will fight maybe medium battles in here, a hard battles, and in here we'll find the final bots. So let me pause the video. I mean, stop the game. I'm going to talk about the turn-based combat onset. So I'm not sure if you've ever played turn-based combat, but it's pretty much like this. So we have, let's say, three characters that we've picked up along our journey. And we have a couple of enemies that we put in the world. We have will not have any time. We'll have the names of our character, will have the HB of our character, the AMP or the mono. This is the magic and we'll be fighting, updating, and each character will have history, and hence the word turn-based combat. And it's actually a very, very modern way of playing games. Don't think it's kind of old and not good. I know some of you might be thinking that why are we not using forks and pitches? Well, actually this is a very modern way of playing games. Many modern games such as, I'm not sure what the name of this. I think this is ExComm something I forgot. Sorry. And this also I forgot, but it's a very highly esteemed game. It has a very high views. You can see you can use items during the battle, which is very nice. And this is also a mature i've, I forgot off the top of my head. Maybe this is Persona 5. Oh, yes, this this is Persona 5. So as you can see, it's a very modern way of playing games and a very tactical way. Also, it gives in-depth play. I tried to make it using forks, but honestly, when you're playing an RPG, a top down to the RPG, it's not that fun, especially when it comes to boss battles. There isn't much room to jump around and play around. So turn-based combat is the perfect combat system for such again, that we are creating. So I will leave you with a challenge to create your own layout. Use the tiles you have or downloaded to create the arena. Make sure the player doesn't go out of bounds and the camera never goes out of bounds. And finally, let me show you what you need to do in here, as we've said, you add the grid, you an prefab it. You add the cameras, the game manager, the player, the level manager, and the audio manager at the music in here to the virtual camera, to the level manager at the background. I don't think we'll need this, but make sure that whenever you are setting your tiles that you have a border where the player can not cross, so it doesn't just walk over, lover and so on. So I'll leave you with your creativity, with all your thinking. Make sure to commit all your changes at the end. And I shouldn't have onstage or I'm going to ignore all the tiles that we've created. And that's it. So I'll leave you to it and I'll see you in the next video.
91. Battle Scene UI: Welcome back my fellow game developers to a brand new video. And as you can see, I've created the layout. I know, again, a very long boring video of laying down your eye. But as always, it's very important if you want, you can go ahead and implement your own battle scene layout. I really, really do recommend that you do that. This is your game. You need to add your own flavor into it. But until then, let's not waste any more time and let's get started. Okay, so now that we've set up our tangent, it's time to set up our battle scene. And how is this battle scene going to look? So let's say we are walking around. We get to a certain battle zone that will create later on. And we are going to start a battle. We are going to change the background. First of all, we are going to set our characters around. And then we'll have a couple of options. First of all, we can either attack, use magic, use our items, or runaway from the battle. And then we will need a separate panel that shows all of the player stats. So how much do we sell each of the players that we are playing with? And I'll show you what I mean by the other players. But first of all, let's get started by creating the panel or the entire battle layer. So we are going to create an empty game object in here. We're going to reset its position and we're going to call this game object the battle scene. We're going to create two layers. So we're going to go into the Edit layer. We're going to create two layers. The first one will be the battle background, and the second one will be the battle characters. So now that we have this done, the next thing to do, now that we're done with this, let's go ahead and import the background. And I found this cool lava and here, so I'm going to use it. You can go ahead and use whichever background that you want. So there we go. This is the lava. I'm going to drag it in here and I'm going to set the sorting layer as the battle background. There we go. If you don't like it, no worries you can use any other. So I'm going to set the scale to be two-by-two so we can cover the entire camera. This is very important or we can make it maybe 1.8 by 1.8. There we go. So we need a big enough picture to cover the entire camera on all sides. And we're going to child this lava to the battle scene and here, and we'll call it the battle background. There we go. Now the next thing we'll do is we're going to right-click on the battle scene game object will go to I, and we're going to create a canvas just for the battle scene. So this will be the battle Canvas, I guess. There we go. Let's double-click and look at how it looks. In here we're going to create a panel. So we'll right-click, go to you, I click on the panel. This will be our menu, menu where we choose what to do with each character. And it's going to be a bit small. We'll put it down here. We'll go into our sprites, sprites, UI elements. This will be our default panel. We're going to turn it up of way. And I can see it down here properly. Why? Oh, there it is. Okay, So this will be the panel that holds all of the attacks that we want to do. So we're going to add a couple of buttons in the menu, so we'll right-click on the menu, go to, I, go to a button and we're going to go to the text first of all, deleted at a text Mesh Pro. And it's going to be called, let's say attack. It's going to be bold, bold, completely black. And the font obviously is going to be the medieval party. And the background of the button will be the one that we're using all the time. And there we go. So this will be our button. We're going to make it a bit bigger. So we'll need four buttons to fit in here. So we need to make sure that we adjust everything. And as I've said, this is always the most tedious part of creating our games UI layout, but it's very important to have a good one. So let me just make this a bit smaller and I'm going to be adjusting the text to fit correctly. There we go. So this will be our first button. Now we need to duplicate it because we'll need for buttons. And we'll go to the menu. We'll add a component in here, which will be the great grid layout group. And we're going to adjust everything from here. So let's increase the cell size. There we go. We'll add a bit of padding on the left, a bit of padding from the top. Maybe increase the cell size by the height as much as we possibly can. Maybe decrease the cell size at a bit of space between them. And there you go. That's about good enough. I think. As I've said, this is all subjective. You can create your own layouts the way you want. So these are our four buttons. Maybe let's increase the cell size on the y. I think that's the most that we can do. And we are going to change this to the attack button. This will be the magic button. So we'll have magic for each of our characters. This is going to be the items. And this will be the Run button. Or let's call this the US items. Use items button. And let's change the text on each one of those. So this is attack. This one is the magic. This one will be the items. And finally, we'll have the run with a couple of exclamation marks. There we go. So now we have our button set up. Now it's time to create the display panel. So I'm going to duplicate the menu. I'm going to move the menu and here make it bigger to all the sides. And we're going to delete all the buttons because we don't need them for now. We're going to call this the player stats. And then here we are going to create three texts names for each of our players. So player one, player two, player three. And under each of these player will have sliders to, first of all, take care of the mannose or how much mana we still have and then how much health each of our players still hat. So let's go ahead and add a text Mesh Pro. First of all, this will be the names. So I'm just going to stop the grid view for now. Turn it off, maybe even reset it and then turn it off. Maybe even remove it completely. But we'll keep it for now. So this will be the text name. For example, let's say it's player name one. And it's going to be of course, the same thing, setting everything completely black. There we go, the player name one. And under year we're going to add the two sliders. So we'll right-click. And first of all, let me create an empty game object for the player. One at the text under here. Or the player one should be really move down here and the text should be reset. So we reset the position of the text relative to the player game object so we can set it in here and we'll just make it a bit bigger. So it's about the size where we want to set the player. Of course, we will be changing this one. We said the grid view, so the player name one for example. And now we're going to right-click and here at a UI slider. So this will be the health Slider. And obviously there are a couple of things that we need to change so the handle can be completely removed. The background will be the slider background that we've added. And the fill area, or the fill, actual fill will be the red slide. So there we go. So now if we go to the health slider, we increase it. There we go, It's working, but there are a couple of things that we need to change. So the background hold down Alt, click on this button on the bottom right. Then go to the fill area. Click here. Hold on. All. Open this up. Nope, that's not good enough. Let me just make sure that everything is working fine. So there you go. As you saw me do, just click on the Fill Hole, click on the anchors in here, hold down Alt so they all go to the edges. And now we need to make a couple of adjustments to fit everything inside of the slider correctly. I know this is a bit tedious, but this isn't necessary. Unfortunately. Not everything you do, something that you love, but it's sometimes necessary. So there we go. Now we have our health slider. Let's click on here. Let's drag it over and make it a bit bigger. So there we go. It looks nice. We are going to duplicate the cells slider and we'll set it down here. This will be the mana slider. And we're going to change the film. So the fill in here is going to be the blue. There we go. As it's set up correctly. Yeah, I think that's good enough. So now if we go to the minor slider and I'm just going to maybe make it a little bit thicker. So add a bit of thickness, so it's more obvious. There we go. And at the Health Bar, also a bit of thickness. There we go. Okay, so this looks kind of nice. Maybe we do need to make it a bit smaller later on. We'll see how we are going to do that. But for now, let's say, there we go, player 1. Let's duplicate the player one. This will be the player two. And if we move it to the right, there we go player to duplicate this again. And okay, so it doesn't fit. We already knew that if we add the grid layout in here, this will be very cumbersome. So if we try to increase the cell size and maybe increase the size like that. So again, I'm adjusting everything according to what needs to be done. So as you can see, I can choose the health and the health slider and demand a slider and make them just a little bit smaller. We can even choose the width that we get in here and copy it and paste it to the Health slider on the second one. And on the third 1 fourth the mana for the mono, and for the rest of everything. And just let's move it. Okay, So I guess this is good enough. Let me just change a couple of values on the health slider so we know that they are actually working. And on the mana, let me change them so we know that they are distinct. So now that we have the player one, we have the player two. And we have Layer 3 with their names, with their health bars, with their mana bars. In the next video, we can start laying out our characters. And you can see down here in the game mode or the game view how this is going to look. So we're going to have the enemies. And here for example, 1, 2, 3, 4, 6 enemies may be. And in here three players, more if you want, if you want to add, for example, for players, five players, you'll need to make sure to add a second panel or squeeze everything in here. And we'll have several options. We can either attack normally with a sword or something. We can use magic. If we have magic or mono, we can use items or we can run away and items can be, for example, equipment equipping a certain weapon. Maybe that might help us defeat a certain type of enemy, or maybe just take a potion, increase our mono, increase our health, and left to fight a couple of seconds more. So I hope you enjoy it. I know these UI laying out videos are very long and boring. That's because it's all based on subjectivity. That's how I laid out. Maybe you want to lay out your world a bit differently. So thank you for bearing with me and I'll see you in the next video.
92. Battle Characters: Welcome back, my fellow game developers. So as you can see, we have created a lot of scary characters and also battle-hardened and ready to fight players. So we have jimmy, Draco and the gram, and we have a master major, blue phase Warlocks and a regular mmh. So we're going to learn how to create all of these. So let's not waste any more time and let's get started. Oh, okay, so time to add some battle characters. First of all, we need these primates. So we're going to go in here, right-click and create a folder for the players, for the potential players will just put all of these in the player's folder. And let's go to the resources and add the enemies. So these will be the enemies will just drag these spreadsheets and here. And I'm going to rename this to the enemies. So there we go, there you can see we have a couple of enemies. Let's go ahead and slice them up. So I'm going to apply that, go to the sprite mode and I'm going to slice up, Let's try it 64 by 64. Nope, that didn't work. So let's try 120 already know what the way we do this usually is we're going to make this a bit bigger. We'll see that the size is 342 by 220. So we'll get our calculator. And in here we're going to take 348 and divide it by four. There you go. So it's 987. And then we're going to take 202, the 0 divided by 2, that's 110. We'll slice this up and there we go. We have perfect slices, slice that up, apply. There we go. So now we have this enemy sprites sliced up. Very good. Now we want to set the default positions for the player and the enemies. So I'm going to go back down here. Let's just make this a bit smaller. And I'm going to turn off the battle Canvas for now so we can see everything more clearly in here. So first off, let's go ahead and right-click create an empty game object which is going to be the player, Let's say player 1 or something. And where is he? There he is. So we're going to move him up here. And then we're going to create a, another game object. And I'll show you why it's a child is going to be the position one and we're going to uncheck that and then child the player to it. And why did we do that? Well, because we wanted the position one to be exactly on the player. So what we did is we created a child on the player that gave us the exact position and then we remove that from. So this is just a quick tip if you want a faster way of doing things. So we're going to go to the player at a sprite renderer. Sprite renderer. There we go. We're going to go to the characters. Players scroll down and we're going to add the player standing still to this one. And we're going to make sure that he is a battle character. So there we go or we can, if you want, make him face the enemies in that direction. I think this one is much better and make sure to move the position to where you want to set your player. We're going to duplicate him. Duplicate them again. So there we go. Now we have three positions for the players to start attacking front. But that to two. This one also to two hours, I mean three, sorry, sorry, sorry, there we go. So now we have position one, position two, position three with a player on each one of them. Of course, we will be changing the sprite later on. But now let's go ahead and create an empty game object in here, which is going to be called the player's positions. And we're going to set these player positions under the player position game object. Let's go ahead and duplicate this one. We're going to move him to the other side. And this will be the enemies positions. So the enemies positions. And in here we are going to of course be changing these names right here to the enemies. Let's see if this works or the enemy enter. Yep, there we go. It worked perfectly honestly. And we're going to of course be changing in the sprites. So I'm just going to be adding in only one that we have for now. So which is this kind of not sure what it is? This weird looking monster will put it in here. And it's a bit small because we need to make sure that it's, let's try 30 to see how big that is apply. He's a bit dark. Yeah, He is a bit dark. Too dark for our liking. We might want to change that. Does he completely not? Let's make sure that he is a no filter. Apply that. I think this is one as a butter and maybe let's try making him 16 with that. Okay. No, no, no, not 1632. Apply. Okay. No worries. We'll maybe moved the position of this one copy, but actually we're going to have six enemies or four. Let's have four. And there we go. So this one is the fourth one. And he's going to be in here. The third one will be here. You can add six if you want. That's no problem. So this one, this one. Let's move him up a bit. And this one will be up here. Let's move the fourth one so he's not completely in the dark. And the third one, there we go. So now we have the enemies, the players. Now we need to create a script that gives, let's say, character to our petal characters. So let's go into our scripts and we're going to create a new folder in here. And it's going to be the battle system folder. So battle systems Enter, open this up. Let's go ahead and create a C-sharp script. And it's going to be the battle. Characters. Hit Enter, wait for it to compile. Okay, so double-click on here. Open Visual Studio. There we go. So now we are ready for battle and has not yet. Anyways, first thing first, we need to establish whether this is a player or this is an enemy, because we said this is a battle character. Enemies are also characters. So it's a, it's going to be a serialized field, a Boolean and is player. So this is going to be, well, if he is a player, this will be true. If not, it's going to be false. Then we are going to create another serialized field, which is going to be an array of strings. And it's going to be the attacks available to that character. So we're not going to have too many attacks. I think fire, ice, maybe some kind of plant attack. I don't know. We'll see. And then the regular slashing attacks. Then we're going to have a couple of characteristics for our players or characters. So it's going to be a public string, the character name. Of course we need the name. Then it's going to be a public Integer. Current HB. So it's the current HP of the character, the max HP of that character, vk, current Mano of the character, and the max man of the character. But not only that, we also need the dexterity that that character has. And we are going to be using this. We're going to be using the dexterity to determine how much force we can apply. We are going to get the difference. We are going to get the weapon power. And we're going to get, of course, the armor difference. And these will all be characteristics that will enhance or change. Or how can I say it? Influence the way or the amount of damage that each character deals or the amount that he can withstand. And finally, we will create a public boolean, which is going to be as that and when the characters that he dies. Okay, so we're going to save that. And now let's go back into Unity o k. So now what we're going to do is we're going to take one of these players, or let's take the, or any player, doesn't matter. We're going to drag the battle character onto this player. And we're going to put a couple of things in here. So for example, this is, a player will add the name. So let's say this will be, this is Jimmy. So this will be V Jimmy. And the rest will be added automatically as we get the information of each character that we are playing with from the player stats. But there comes the enemies. The enemies don't have player stats on them. So we are going to have to do this manually for each one of them. So we drag, we've set it on the enemy, and now we are going to start applying all of the changes on the enemy. So I'm going to issue with to you as a challenge to create an enemy stats. So add script to the enemies and the prefab them and set a couple of stats for those enemies. And obviously I've shown you a couple of sprites. Go ahead, use your own sprites if you've got enemies that you want to add to your game at characteristics to them. And the prefab them because we are going to be using them later on. So pause the video right now and go create your enemies. Okay, welcome back. So as you can see, I've created for, let's call them monsters. We have the Warlocks, the mage, the master, and the blue face. And this is the blue phase, this one as the master Warlocks and the major. And I've also created three players. So we have jimmy, we have Draco, and we have the grim. And grim is a reference to Billy and Maddie grant on Cartoon Network. If you haven't watched it. I don't know what you did in your childhood. But anyways, we've created three characters. And if the players don't have any special status, will be updating them automatically. And they are players, but the enemies each have their own status. So you can see, for example, the master mage has all 66 sixes because he is, I don't know, some kind of demon. Then we have the Warlocks. He has more mana than HP and let's say less dexterity and defense, but much more a weapon power, for example. And we have the major which has normal defenses and so on. Defense no, he doesn't have many differences because I feel he has a weak body for some reason, but he has a lot of weapon power because he has those balls, I don't know. And the blue phase, which is a very, should be a very easy character to deal with. So this is just off the top of my head, how I am thinking, how I'm doing. I hope you create your own characters at your own stats to each of the enemies. And I hope you're having fun because in the next video we'll actually be starting a battle. So I'll see you then.
93. Starting A Battle: Welcome back my fellow game developers to a brand new video where we will be actually starting our battle. So let's run the game. Let's say we are walking around so we get to this position and oh no, a battle starts. Well, I've done it manually. I've pressed the BP, but as you can see, we start the battle and not only that, we can no longer move Jimmy around until the battle is finished. So let's not waste any more time and let's get started. Oh, okay, So now it's time to start a couple of battles. The first thing to do, obviously, is to go ahead and create a battle manager. But before we do that, we're going to create an empty game object in here, and it's going to be the bad manager. We're going to reset its position. And we're going to chart the battle scene to the battle manager. And we're going to go into the battle background and make sure that its position is 00. Don't worry about that. We're going to move everything later on or just skip it for now and here and we'll see we're going to deal with everything and just stay but 0 case. So now back in our scripts and the battle system, we're going to create a battle manager. So patho manager, hit Enter, wait for it to compile. Nope, we don't need to open this. Okay, and we're going to drag it, of course, and to the battle manager game object. And we're going to open up this group. So we're going to need a couple of things. So I'm going to go through them and tell you everything. First of all, we will need an instance. So public, static, but Manager Instance, save that. Then we need a variable that keeps track if a battle is active or not. So we're going to make it private because it's going to be dynamically changed. And it's going to be, is battle active true? It is active, false, it's not active. Then we need a reference to the battle scene. So we're going to create a serialized game object battle scene. Then we need a reference to the player's position. Positions. So it's going to be of type transform. And of course is going to be an array because we have several of those and it's going to be the player positions or player's positions. It's a better name. Of course we need also the enemies positions. Enemies positions, and will need a reference to all the battle characters available, the enemies and the players. So I'm going to create a serialized field in here, which is going to be of type battle characters. It's going to be an array, and it's going to be the player prefabs because we are going to be instantiating them. We don't want to always have the same players, always in here playing. We want to instantiate them dynamically based on where we go. And we're going to create player prefabs and the enemies. Prefabs need a semicolon in here. And we could have put all of this on the same line. So I'm going to delete and add a comma. So we save a bit of space because this is going to be our biggest script yet. And finally, we need and start to set the instance to this instance equals this, save that. And then we're not going to destroy the onload. Maybe we don't even need this because we'll see in just a bit, but let's just keep it. Next. We want a method to start the battle. So I'm going to create a public void. Start battle and what do we need and start bat? Well, first of all, we need parameters to know which enemies were going to spot, spot, spot. I'm not sure how it's called. Which enemies are we going to instantiate? So the players are already all available. So let's say we are walking down a dungeon. We don't want to spend random players. We already know who we've taken on the journey with us, but we don't know which enemies are going to come out and tangent. So we're going to create a string. And it's going to be an array of strings and the enemies to spot. Okay, so we're going to check in here. If there is no battle. So if there is no battle, then we are going to set the battle active to true. And we also want to stop our character from moving or doing anything. So we're working with Jimmy. We start a battle. We open up the battle scene, but we don't want to be able to move with Jimmy. So again, we are going to go into the game manager and we're going to add yet another Boolean in here, which is going to be the battle, is active. Save that. And if it is active. Then in here we'll add a condition that the battle is active. We'll save that now back. And our battle manager, when we said the battle active to true, we are going to access the game manager dot instance. The battle is active to be equal to true, or it can be equal to as battle active. Or we can access the battle manager from here. But we'll just give the game manager as simple as possible. So we're going to save that. And finally, we need to actually turn on the battle scene. So battle scene that set active to true. Save that. And now finally, we need to actually start the battle after we press some key. So I'm going to issue it to you as a challenge. And your challenge is to start the battle. So take a key input and update and call the battle start method. And to create a new string array, because you will be adding a string array, you will need to write inside of the parameter new string, add the brackets and the string names. So pause the video right now and go do the challenge. Oh, hey, welcome back. How did you get all of that? So in here we're going to create an if condition and we're going to check for an input dot, get key. And of course get keydown and then keycode dot, I think B is an appropriate letter to press or key to press. And then we'll call upon the battle start. So battles start or Start button. Sure why not? We can start battle. And in here we'll need a string. We need to send a string array. So we're going to create a new string. And we're going to open the brackets just like I showed you on the syntax, whereas the curly brackets. And in here we are going to write the names of the enemies that we want to add. But a small thing to keep in mind that we need 100% correct names. So we're going to go in here and to unity as soon as it allows us to case. Thank you. So where are our prefabs? But two characters, enemies, mage, the master major, we copy this, we paste it in here, and then again we copy the, Add a Warlocks, copy this, ad him in here, save that. And now let's go into Unity and test this out. So we're going to first of all turn off the battle scene. Oh, we need to assign all the variables so the player positions. Let's open this up and lock this window down, select the player positions, drag them in to the player positions. Select all of the enemy positions, drag them into the enemy positions. Let's select all the enemy prefab, drag them into the enemy prefabs, and go to the players. And we'll do the exact same. So as you can see now we have everything set up in here. And finally, we need the battle scene. There you go. That's the battle scene. We are going to go ahead and turn all of the positions of or actually all the enemies inside of here, off. There we go. Why did everything get to an O? Because okay. So as you saw, because I've logged the battle manager in here, when I clicked, I thought I turned off only the enemies. So everything got turned off. This is one of the, you might think this was stupid and it was but trust me, you will fall for that once every once and awhile. Anyways, everything has been turned off the battle background. Okay. So Manager battle scene, I'm going to turn off the battle scene. I'm going to run the game and there is an error, which is a semicolon. Okay, Sorry for that back in our game. What's the problem in here? I don't think there is any problem. We're going to run our game. This is an arrow that just showed up. There we go. We walk around when we hit the B key. Okay, so as you can see, I cannot move any longer. Our battle scene has activated, but it's not in the correct position. So let's go ahead and move it. So in battle start, we turn on the battle scene or dried before we activate the battle scene in here, we are going to go ahead and get the transform. Dot position will equal new vector three. What's the position that we are looking to go to? Well, it's the camera because we have a follower count. So wherever our player is, we want to put the battle manager game object right on top of it. So we're going to access the camera dot domain. So camera dot main, this is the main camera and it's the one that we're actually in needing to access the transformed position x comma duplicate, duplicate. And you know the drill. Why z and with, I don't think we even need this. We can keep it as the transformed position, z transform position. And actually not only that, no, we need, we have to make sure that we don't put the zed of the camera. Because if we go back in here, we look at the camera, look where does that is. So it's at 12.4 and the main camera is at minus 1.33. So make sure I'm in the zed is at minus ten. So we need to make sure that we don't access that the z component or this app component, we'll save that. Well had an Enter save that back in our game. We run the game. We move around, Let's move to another side. So we are here when we hit the B key. Okay, we don't see anything for some reason, whereas the main camera. So let's try this again one more time. Why did we move to a very bad position? So B, C, it's around the main cameras, 1013, NDB key. Okay, so something is not correct. The transformed position of the camera. Oh, okay, so the problem was if we click on the battle background, you'll see right here that the battle background is at 11.06. So what we'll need to do is set it to 0. So now when we run our game, we move our character. Let's say we step over right here, hit the beak. There you go. It's right in front of us. Sure, we still don't have any players or enemies, but we'll be doing that in the next video. So if you're enjoying the course, if you like me as an instructor, if you're having fun, please do leave me a review. It helped me out a lot and I'll see you in the next video.
94. Adding Players: Welcome back, My favorite game developers and this video and we run our game. You can see that we have Draco and here we have the gradient here we can even move him. We need to fix that. We need to also flex the colliders on them both. So when we hit the B key, start the battle. There you go. You can see that all the active characters in our scene are now ready for battle. So let's not waste any more time and let's get started. Oh, okay, So now it's time to start adding players and enemies. So let's start by adding the players. Who are the players? Well, they are. Let me just take you where as our prefabs, battle characters players, these are our players. So what we'll do is we're going to create these players in our game. And then we are going to find them using the game manager and add them to the player stats, which is in here. So we're going to find them, add them to the player stats, then call upon the game manager, get the player stats from him, and add them in our battle manager. So first off, we'll need to go into the Prefabs at the player. And here we're going to set him right here. We're going to add the dark monster. I'm not sure what his name is. Oh, Draco. Draco. He has some player stats his name as Draco. And Draco here enter and he has, let's see, current XP, I don't know, maybe 72, Max HP, maybe 250 with a current HP of 250, maxmin is 10, 10, 10. Let's see dexterity. I think he has more dexterity, sold 40 defense. He has a big armor, so I guess it's ten. And that's it. And later on we'll see what happens he can wield, so we'll save that. And now we are going to add him and to the prefab. So let's create a folder for the players. Well, that's the player and to the players. And then we'll get Draco and add him in here and create an original prefab. So hit Enter. Now we have Draco that's add a second one which is going to be the 0. And before we forget on Draco, we have the sprite renderer. We don't want to have the player script on him, so we're going to remove the player script, remove the animate two, and that's it. I think that's enough. And we're going to move Draco up here. So next door is a bit too big, maybe our unknowns, but no worries about that will put him in here. And then the second player, where is he? Player? There we go. He's here. It's going to be the skeleton. So let's go look for the skeleton. Oh, and before we forget, the, the character image should also be changed. So we're going to make sure that this is the character image and we're going to apply that change. Okay, I think that's all that we need to do for Draco. Let's do the same for the skeletons. So where were we? The player won. The grim. Copy that. Paste it in here. Enter. Let's see, we need to choose one of the images. Who should we just choose this one? And we'll add it also in here, will move the gram appearing next to Draco. And what should we add in here? So what's the max HP? I think it should be infinite as he's a skeleton. Or let's make some kind of magic skeleton. So the HP is going to be low. So we're going to make 7070, let's say 120. 120 dexterity. Let's say 30 or no, no. Let's make him 50. And the difference is warranty. And there we go, we save that. And we'll also remove the animator and remove the player component. And we're going to create a prefab out of him. So we'll go into the layers and we're going to add the grim as an old original prefab will save that. Okay, great, so now we are ready. Let's go into our scripts, into the battle manager. And we're going to extract this method in here just to keep everything clean. Because as I've said, will be one of the longer scripts we're going to create. So this will be the setting up battle, hit Enter, and we can even close it off to save it but space, keep everything very clean. So in here we are going to, first of all, as I've said, go through all of the players stats on the game manager. So we're going to create a for loop that's going to go and I equals 0, I is less than v0. Game Manager dot instance, dot player stats, dot length. This is a method dot length and will increase by one every single time. In here we're going to check if the player's stat that we're trying to access or the game object of that players that is actually active in the hierarchy. So we're going to check if a manager dot instance, dot player stats. At the position I dot is act or dot, game object, dot, active and hierarchy. Then we are going to loop through our prefabs and see if we have that character available. So we're going to again create a loop inside because we don't want to actually instantiate the prefab. We have the prefab and here let me show you again. The prefab in here is different than the battle character that we went to instantiate. So we want to get the name. And based on that name, we want to go to the Prefabs that are on the battle manager. So we're z the player prefabs. There we go. And then we want to check if we have that prefab available. And then we are going to set it with a battle character on him. So that's the difference between the regular player and a battle character. So we're, are looping through. So because we are already using AI, we're going to use j. And you can use any kind of variable you want. You can even name it something that's more sophisticated and more indicative of what we are looping through, but I don't think it's necessary for now. So for j equals 0 and j is less than the player prefabs. Player prefabs dot length. That's because we are looping through the player prefabs and this should be j. We are going to check if the player prefabs at the position j that we are looking through, the dot character name is equal to the game manager, for instance, dot player stats. And I think we could have actually said this player stats somewhere in here and really made this much simpler. No worries about that for now, Let's search through a certain position which is going to be on the eye. Because remember, the I is looping through the player stats on the game manager dot player name. And if there is one of those, then we are going to create a new battle character, new player. And it's going to be equal to an end here we are going to instantiate. But not only are we going to instantiate with previously instantiated without adding any rotation or position. But this time we actually need a certain position to place our new player. And so we're going to instantiate. And instantiate will open up the brackets. Hit Enter. We are going to first of all, write down the player prefab at position j. So if you don't remember the format of the Instantiate, you can see it in here. You can see that we have many variations. So we can add one parent with a position and the rotation and also a parent. So we are looking to set the original. And here that's the object that we want to instantiate the position which we're going to put as the position that we've created for the players in the previous video, the rotation, which is going to be very simple and then the parent. So what is the position? It's going to be the player position. At position I, the position. Then we are going to access the player position at position I in the array. And we're going to just set it as the rotation, which will give us the default rotation of the transform. Don't want to change it. And finally, we want to set the parent as the player dot position. There we go. We save that. So hopefully you know what we're doing in here. We're getting the object, the prefab that we want to instantiate. We are setting him to the position that we've set in our game with setting for the, let me show you what I mean. So remember when we created the positions in here, player position 1, 2, 3, we've added them right here. There they are in the player position, so we're setting them to be the same as here, as setting them with the same rotation and the same parent and making sure, I mean, sorry that the parent is the position at. So for example, this will become the parent of the player that we are instantiating. Okay, great. So these are turned off. We can even delete them. We don't need them, but we keep them just to make sure we are in the correct position. Well, that thoroughly explained. Now we want to track our characters and for that we are going to create a list. So we want to keep track of the active characters. And that's going to be, of course, a challenge for you. And your challenge is going to be to create a list. So create a variable that is a list of type battle characters. This will be the list that keeps track of the active characters and you'll need to initialize it. Finally, add layers to the list in the method we've created. So create the list and instantiate it using new list. Sure you know that by now. And finally, after we finished creating the player or setting up the player or adding the player whatever you wanna call it, make sure to add them to the act of characters list. So pause the video right now and go do the challenge. Okay, welcome back. I hope that wasn't so hard. Will move up. And here we are going to, let's create an INR, so serialized field. It's a list of type battle characters. And it's going to be called the active characters or active bachelors or whatever you wanna call them. And it's going to be a list of battle characters. So this is where we instantiated. Now it's time to add to that list. And after we finish creating and instantiating and setting everything up, then we are going to add this new player that we've created to the list. And we'll do that by calling the active characters dot add. And this, as you can see, ads, any element or any item of type, battle character. So dot add. There we go. You can see it. Enter open the brackets and add the new player. So we're going to save that. Let's go back in here. Let's run our gain and let's see if they instantiate. So as you can see, we have the characters in here. We can move him because, because these are still has a rigid body, remove them. That's funny. So and we need of course to change the color there is, but for now we're not going to worry about that. So if we go to this point, we hit the BP and we have the characters being updated up here. Why is that? Because let us go to the battle manager and the battle scene. V player position. So the player position for some reason is up there. Even though it should have been here. That's turns off. Stop this. So the player position is at 000. Let us see what's going on. So the player position is at the position 0, but the position one is up here. So we'll need to change a bit. So we're going to make sure that the player's position. Let's see, let's see. So we are putting the transform that position at the position of the camera, and it's the battle manager. So it's this entire battle manager which is currently at 0. The battle scene is at 0, the battle position is at 0. So now all of these three positions need to be moved down here to 0. This will change all of them, so we'll just move them as one object. And now there we go, These are in here. Let's save that. Let's try that again. Maybe we should modify it later on. So I'm just going to hit the B key. There we go. As you saw, we need to modify just a little bit more. And we'll put them down a bit. Run the game. Let's move around just to make sure it's not about the position of the player. There we go, so they are in the correct position. We've loaded them. And you can see right here the grim Draco and Jim. So I hope you enjoy it. I hope you've set everything up. Maybe their positions still need a bit more modifications, but I think that's good enough for now. And the next video we will be adding our enemies to the game. So I'll see you then. And by the way, before I go, there is one little trick that we can do in here. So let's say we choose all of these positions. We want to set them right here, okay, so what is the position in here for those players? We can actually choose one of them or choose. For example, let me just see. Click in here and copy the position. Exit the game. Choose these again. Click in here, paste the positions. And hopefully this works. I'm not sure if that will work. Let's run the game. Maybe you should do for each one of them had been upcase. Obviously that did not work. So now each one of those should be on a separate position. And we'll just move it a bit to the right, the right and upwards. Say that again. At the beaker. Yep, There we go. I think that's good enough for now. So commit your changes, and I'll see you in the next video.
95. Adding Enemies: Welcome back my fellow game developers to a brand new video. And in this one, when we run the game, you'll notice that when we start a battle, 00, now there are enemies who solves carry. So now we are no longer alone with our players and the background. We also have our enemies locked and loaded to start killing us, but we will not lack them. Until then. Let's not waste any more time and let's get started. Oh, okay, So now that we are adding players, it's time to start adding the enemies. But before we do that, there is one very important thing that we need to do and that is we want to import the player stats. So let's go ahead and do that. And right after we add the new player to the act of characters, we are going to part importing the player stats. So in here we'll create the player stats. This will be a variable which we'll just call the player. We need a variable to keep track of everything. So we don't keep writing it every single time. And it's going to be equal to the game manager dot instance, that layer stats at position i. So now we have reference to the GameManager player stats one. Then we are going to add everything up. So if you want, you can go ahead and do this on your own, see who can do it faster. And let's get started. So the current HP, I'm not going to say much because we already know the drill in here. I might even skip over the sparked. Okay, there we go. So we've imported all of the stats. But as you can see, we are starting to get a very ugly start battle. So we are going to extract these lines in here. We're going to right-click quick actions and refactoring. And we're going to extract the method. And notice how smart it is, because we are using the Ion here obviously, and the I is only available through this loop right here. What happens now is Visual Studio will actually create a method that takes in an argument I. So that is super-helpful and we're going to call this the import layer. Stats hit Enter, and there we go. So now we have the important player stats. And then again, we are going to choose all of the code in here, right? Click quick action and refactoring, extract the method. And this is going to be the adding layers. So how cool is that? Now when the battle starts with setting up the battle, we should have setup the battle, adding players. And then inside of adding players, we loop through, we choose the prefabs, we instantiate them, we add them to the active character. We then import the player stats which is here, and we do all of this and so on. So as you can see, everything is clean, cut and understandable. It's very easy to read. But the next step is to actually start adding the enemies. And again, I'm already too tired to do this. So it's going to be your challenge, Don't worry, it's pretty similar to how we add the players. So you'll need to loop through the enemies that you want. You need to make sure the field is not empty because we don't want any empty and amines. Then you'll need to create a second loop to loop through the enemy prefabs, just like we did in the previous. When we wanted to add, the players will need to compare the character name prefabs, enemies spawn. And you'll need to instantiate the enemy if there is a match and if we, if we fall for some reason, put the position of the enemies in the wrong place which never happened. Then you'll need to also adjust them manually in Unity. Pause the video right now and go do the challenge. Okay, welcome back. So we're going to start by looping through. Equals 0. I less than the enemies spawn dot length. So we're getting the enemies to spawn right here. And we are going to add one to it every single time. Then we're going to check if the enemies spawn isn't empty. At position i of course, because we don't want to check for everything. We want to check for a certain position. And this is how we check if a string is empty or not. I hope you didn't get stumbled on the spot. Then we're going to create a loop and side of j That's going to loop through all the prefabs. And j plus plus. And then we are going to check the center machine cameras off. If the enemy prefabs at the position j dot character name is equal to the enemies spawn at position I. That means that we can instantiate a new enemy, which is going to be of type battle characters. And we'll call it new enemy. It's going to be equal to instantiate in. Then she gate, open the brackets, add an entering here. It's going to be, the object is going to be the enemy prefab at the position j, and the enemy position at eye position. What is this? An amine? An amine is position I got position rotation. And finally, the parents should be the enemy position at the eye. There we go, we save that. And we'll also going to add them to the active characters. So active characters dot add as the enemy, it's the new enemy. There we go. Close that off, save that back in Unity. I hope you understood this. It's almost 100% the same as adding a player's. We just go through different kinds of enemy prefabs. We check if it's different than 0 or different than empty. So because we don't want to add something that is empty. And this is just a small check in here. So back in Unity, save that. Let's run the game. So we start the battle, but it wants, oh, well, it started the leaky. There we go. There is nothing is there any enemies? Is there anybody out there? Yep, there we go. We have the Warlocks, the main page, and nothing else. And where are they? Where are you? Where the hell is that? Oh, so they're up there. Ok, OK, OK, OK. So we'll need to move all of these down. And let's see enemy position. Why is there? So these are the enemy position. Maybe it should be set back to 0. Let's set it back to 0. 0, no, no, no, it shouldn't be at 0. Or maybe should, why shouldn't it? So we're going to move all of the player's position to the rider. But and then we are going to maybe move them down, run the game. And this should have been more well organized, but no worries about that. Let's move them down. I'm I'm moving just hold down, shift, click on all of them, move them down somewhere. Somehow run the game. Had the BP. Oops, there are still up there. Yep, There we go. This is how they should be looking like. So we're going to exit the game. Those again, move them down, but move them to the right. Run the game. Had to be, there we go. These are our enemies standing right in front of us. So I hope you enjoy it. I hope you did the challenge. I hope it wasn't too hard. I hope you're not annoyed by the reasons why these are not very well aligned. Maybe there is a quicker fix, maybe we'll find it later on. I hope you are enjoying, I hope you're committing your changes and I'll see you in the next video.
96. Putting The Turn In TurnBased Combat System: Welcome back My favorite game developers to a brand new video and this one, when we run the game. When we start the battle, we have the enemies, we have the buttons, we can attack, get items, run the magic, Very cool. You can see that we have a turn in here. So when we had the Anki once, twice, when it comes to the third time, because now the enemies are attacking, we don't have access to the balance. So now only the enemies attack us. There we go. And then when we finish, because we have five characters, we start the turn of course at 0. So now when we want to go to five, we go back to 0. We are back at the skeleton and we can again access our buttons and attack items, run magic and so on. So let's not waste any more time, and let's get started. Okay, now it's time to put the turn in turn-based combat. That's a bad joke. Let's get started. First of all, there was a slight problem in here when we are setting up the battle. We actually put this condition inside of here. But we need to make sure, and we need to know also that when we start a battle, we need to make sure that there is a battle active for all of these. So we're going to remove the condition from here. We're going to add it up here. And we're going to remove this bracket and hit Shift tab. There we go. Shift the clean all the whitespaces in here. And there we go. Everything should be correct right now. And finally, we are going to add one more of these in here. And everything is good that I make. Smaller, really. Okay, So can you see this clearly? Okay. Anyways, let's continue on. Let's extract this method also. This is the adding enemies. So right-click, click Actions and refactoring, extract method adding enemies. And as you can see, we also get the enemies spawn sent to this method and here and even creates everything. So how cool is that? I think that is really cool. You can see that they are all down here importing, adding, setting, etc. Okay, to business. Now we need to put the turn and combat, turn-based combat. We are going to create, first of all, an integer that keeps count, so it's the current term. And then we are going to create a boolean, which is going to be keeping track if we are waiting for our turn as players. So waiting for a turn. If we are waiting for turn, there are a couple of things that we can do. We're going to save that. And finally, we need to also get a serialized field of a game object, which is the UI button holder. So UI button older. And why do we need this? Well, because when it's not the player's turn, we want, we don't want the buttons to be available for them to press. So this is a slot that we are going to fill. And by the way, these two variables don't need to be serialized fields, but we want to put them as such because we want to make sure that everything is working correctly. So now an update, we are going to check if it is battle active. So we are in an active battle. And if we are waiting for turn, then that was, then we are going to check if the active character at the current turn is a player. But we can't really know if it's a player because the player in here is a serialized field. So we can maybe make it public. But no, we have a much better way. And it's going to be a challenge which is to return the player. So create a method in battle character script that returns if the character is a player. So pause the video right now. Do the challenge. And if you want to go an extra mile after you finish checking if the character active character on the stern. As a player, then turn on the buttons. If not, turn them off. Welcome back. That was a fairly simple challenge, I believe so we're going to create a public bool. Is player, return, is player. Back in here. Is player. If it's true, that's just. This. And if it's true, then the UI button holder 0 true. Else UI button holder. But sad, active, false. Save that. Okay, great with that done the next step is to have a manual way of adding a turn. So we're going to end here, check for input. If input, but get key down. Key code, which keycode haven't been used yet. And I believe we haven't used and this will represent the next term. So in here, what do we do every time we go to the next term? Actually, let's create the method. So next, turn. And we are going to create it in here. Where should we added the battle starts? Should stay with these four. Let's add it down here. So it's going to be a private or maybe public. Let's keep it private if we do need it and another script, we can easily make it public, but I don't think so. So private, void. Next turn. And what are we doing in here? Well, first of all, we need to set the current term plus, plus. We are increasing it by one. But there is one more thing that we need to keep track of. And that is if the current turn to get some greater than the active characters count. So if the current turn please, is greater than or equal to the act of characters dot count. What will we do now? We will set it back to 0. So what is happening in all of this? First of all, we start off by checking if we are in an active battle and we are waiting for our turn. So waiting for turn can be applied both to the active characters, which are players and enemies, so that they don't attack, they wait for their turn to get there. We are checking the act of characters on the current term. So the current term goes through all the players then all the enemies. Why? Because we are first of all, I think the players, and we add them in here into the active characters list. Then we add the enemies, which we do later on. So first of all, we have a list of all the players. Then under them, immediately we have all the enemies. So we are going through them. We check using the current turn. Get the active character. If he is a player, then we have the button holder. If is not a player, that's an enemy, we can't attack. We shouldn't see the buttons holder to avoid any problems. And we go to the next turn every single time. How do we do that by increasing it by one? And then if it gets over a certain limit, we stop. One more thing that we need to take into account is that when we start our game, when we are starting the battle, we need to make sure that waiting for turn is true. And that the current term is. Now in here. You can say it's either 0. So there we go. We immediately start with a player with the main character, the main player. Or we can create a random range. So random that range, and so on. It's going to be between 0 and the active characters.com. Now, I believe that this is a much better way of starting a battle and when it comes to the actual game. But for testing purposes, I'd rather have it start at 0. So we can always make sure that we can hit the End key to go to wherever we want and not just having it starts somewhere randomly. So with that done, we're going to save, I'm going to keep this in here as a comment for those of you that want to have a random character starts attacking when the battle starts, we are going to go into Unity. I'm going to take a breath. Okay, now we're going to run our game. We are going to go to the battle manager. We have the current term as 0. We are not waiting for any term. We have the beak. Now we are waiting for a turn. When we hit the Anki, we go to turn number one, then number 2345678. And obviously we don't see the battle Canvas because we've turned it off. There you go. So now let's try this again. We didn't add the holder. Why was the battle Canvas turned off that I just noticed that menu. Let's turn on the battle Canvas. Scene turned on and the US, whereas the menu. So this is the menu, it has all the buttons. Now, we could turn off the entire menu, but I think it's better to just create a game object. O, but we have the menu that has the grid, right? Okay, So the grid layout, Let's turn off the entire menu. That's no biggie. And let's just add the menu when it's our turn, the managers disappears. You can though, but you need to move the grid layout, make sure that you do that. So we'll save that. We are going to turn out the battle scene, run our game. Go to the battle. There you go. So now when we where's the bathroom manager? So turn to 0. When we get to turn one, we are at maybe we started at the skeleton now we are at mister I don't know. Then a Jimmy, then there we go. We cannot click the buttons anymore. Again. We go through these two. We are back at 0 at the skeleton and we can use our button. So everything is working. I hope you're enjoying this course. I hope you'll learn a valuable lesson today. I'm not sure what that was. Something about maybe moving turns. Anyways, we are going to commit our changes. Now. We the turn in turn based combat, combat of our changes. And I'll see you in the next video.
97. Taking Turns : Welcome back, my fellow game developers. I don't have anything to show you. We just do a couple of things. We update the battled, we check if the players are that we lose if the enemies or that we went and we can't implemented yet because none of us can attack. But in the next video, we'll also make sure that the enemy can attack and make sure that it works. But this is a very crucial video and one that requires a lot of concentration from it. So put your thinking caps on, put your concentration gene zone. Is that even a word? And let's get started. Oh, okay, So now we are moving from turn to turn. But what is actually happening? Well, nothing. What are we doing in between turns currently nothing. But we are going to each term update the battle. So let's go ahead and update the battle. What do I mean by Update button? We go through all the act of characters. We check who has some current HP that is 0. If it has 0, we are going to kill that character. And then we are going to also check if all of the, let's say enemies are dead, then we win the battle. If all the players are dead, then we lose the battle. So let's get started. We are going to open up our script. And in here, in the next term is where we update the battle. But before we do that, we need to make sure that the waiting for turn is set to true. So we are actually waiting for a turn. And then we are going to update battle, close that. And now we are going to generate this method. There we go, update battle. So what are we doing in here? First of all, we are going to create two variables. And I'll tell you when we create them or they are. So bool enemies or let's call it all. Enemies are that and it's equal to true. And a second one. All players are that. So can you please move out of the way? Thank you. All players are debt. And why is this true? Well, as we scroll down, it'll see by the end of this update battle, it's going to be quite a big method. You'll see that we are going to go through all the HP of the active characters. And if one of them has an HP that is different than 0, then we are going to set one of these to false and we are not going to enter into the condition. We'll see how that looks like as we go on for now. You'll need to trust me. So we are going to create a for loop, which is an int from 0 less than the active characters dot length, dot count because it's not an array, it's a list. And we're going to add one to it every single time. Then we are going to check if the active characters at position I, the current HP, is less than 0. If it is, then we are going to set it to 0. Why are we doing this? Well, because if we look in here, nothing here actually, you, when we turn on the panel, you remember we have that bar of the players. We don't want it to become negative. So we want to make sure that when it gets to less than 0, because sometimes the damage that we apply can take the HP to less than 0. We want to set it back to 0. So active character at the position I, what is there always API it because the square brackets on next to it can't HP is equal to 0. Then we continue on f V, active character dot AHP is equal to 0. Then we are going to kill the character in here. So I'll just add a comment, kill characters or character or whatever. Okay? But if it's not, so if the character dot I dot current HP is not equal to 0, then we're going to create an else in here. And we are going to check if that character that doesn't have an H B that is equal to 0 is a player. So if the active character dot I dot is player, we are going to set v all players that to false. And if it's the else, if S is the enemy, than all the enemies are equal to false. They are not all that there is still one of them alive. So why are we going through all this trouble? Because we, we don't want to go every time through all the enemies and then check that they are all alive. We think that all of them are dead. And then if one of them is alive, then they are no longer that. And we can continue the game because we need to either have all the players that to lose the game or all the enemies that to win it. Okay, so again, let's go one more time how this code is working. We are going through the characters. We are first of all, checking if it's less than 0, we are setting it to 0. We don't want any negative numbers. I'm going to remove the brackets, keep it simple. Then we are checking if it is equal to 0. So this condition must have gone through this. Or for example, maybe for a coincidence it doesn't go under, it's exactly 0. No worries about that. We kill the character. Else. If it's not that then we are checking if it's a player or if it's an enemy. If it's a player, we said that all the players are in that yet, if it's an enemy, that all the enemies are in that. Yet. Now in here, after we finish looping through, we need to check for the enemies and the players and then decide whether we won or lost. And that's going to be part of your challenge. Check the debt. And first of all, you will need to create a condition that checks if all the enemies or all the players are that, then you'll need to print a winning or losing message. And I'm going to give you a hint on how can you add an or. You will need to check for all using these two symbols. So pause the video right now and go do the challenge. Okay, welcome back. So first thing first, we check if enemies are that or all enemies are dead, or all players or that. Then we enter into this condition. We check if it was all the enemies, then we are going to print out we won. Else. That means that it's all the players. We are going to print. We lost. Or we can also, I think else if all players are that, then we are going to print we lost. This is just for an extra step of safety. And finally, what happens after we finish? We're going to exit outside of you. We are going to access the battle scene and we're turning it off. So we need to add the semicolon. Battle scene. Dots are active, false. And we are going to access the game manager and make sure that the player can walk again. Battle is active as equal to false. So now the player can walk again. And finally, the is battle active is set to false. Great, so let's save that. And unfortunately there's yet no way to test this until one of us, either us or the enemy attacks. So in the next video, we are going to make sure that the enemy can attack. I'll see you in that video and make sure to commit all of your changes and goodbye.
98. Attacking With Enemies: Welcome back, my fellow game developers. In this video, we've made the turn based combat more automatic and dynamics. So when we start the battle, we can see that the term 0 turns one determinists to now when determines 3, it turns off and you can see that the turn goes by it's own and then again by its own and goes back to 0 because the enemies have finished attacking. So how exciting is that? He has? I know, I know. Let's not waste any more time and let's get started. O k. So we want to wait between every single enemy attack. That means that we need a co-working. Why do we do that? Well, because we don't want to make the enemy attack like popup, pop and then it's gone. No, we want to get a popup. Now we want to have pope than realise what happens. See our life gets a bit smaller, see where the damage was dealt. And 10 again. So that's what we want to do. For that, we are going to need to create a co-routine. And for that, I'm going to issue you a challenge. And your challenge is to create a coating. So setup the weighting for turned to false. This set the weighting termed false. This is at the beginning of the coroutine. Then you'll need to wait for 1 second. Then you'll need to call enemy attack method are created later. Then you'll need to wait another second and then you will call the next term. So with all of that information, pause the video right now. You can even add one more point in here. And if you want to think of an extra step that you want to do, where do you call this courting? Anyways, for now, your challenge is to create the score routine. Pause the video right now, and go do the challenge. Okay, welcome back. So where are we? We are going to close down the next term, close down the update battle. And in here we are going to create the coroutine. So it's a public eye enumerator. And it's going to be the enemy move co-routine because it's the move of the enemy. So we are going to first of all, set the weighting to false. Then we are going to yield, return. New. Wait four seconds, 1 second. Then we are going to NMI, that will create it and just a bit. Then we'll yield return, wait for new again. And then we are going to go to the next term. Okay, great. Let's go ahead and extract this or generate this method. So in here we are going to do a couple of things. First of all, we want a list of all the players that we can attack. So we'll create a list of type. And because we are going through the indexes for now, I'll show you what I mean in just a bit. So the players equals a new list of int. And now we want to go to a random range. Now, we don't want to go, for example, always to the 0. So we want to have a random range of players. So we're going to create a variable in here that's going to be the selected layer to attack. And it's going to be equal to the players that we have at a random dot range. Random random that range. Why are you not giving me the range? Hope. Okay, welcome back. So random.randrange. I made it work by force. What's the problem in here? It was confused between, as you can see, Unity engine dot random and the using system, System.out random. So I just comment the system out hopefully will not have many problems from this. Let's continue on random.randrange. We have the minimum. So what's the minimum? It's the 0 because we start at 0 from the number of players and then the players. But count. And we close this off and if you forgot what players is, where is it? We set it somewhere in here where we created the list. Okay, So the listing here, we choose from the players that we have. And now what we're going to do is go through a for loop. And it's going to go through the active characters, dot count, increasing I every single time. We're going to check if it's a player. So active character at position i dot as a player, and his HB is greater than 0. Then we are going to add to the players VI. So what do we have now? We have a list of players that we can choose from randomly to attack by adding their position to this list of integers, then selecting one of them to get attacked. With that done, the final thing that we need to make sure of is that we actually call the enemy co-routine. And that's going to happen in here. After we set the button to be false, we can go ahead and open up the curly brackets in here. And we are going to go ahead and call the coating. So start co-routine enemy move, courting. So when we turn off the button, we have the coating and we're going to extract this method just to keep it all clean. It's going to be called Activate layer buttons. Is that a good name? Or check for activating Player buttons or check button holders, check layer button holders had entered. And I'm going to move this method. Where should I move a or should I keep it in here though? Let's keep it here. Let's keep it here. We have the start battle, the enemy move, Curtin, save all of that. Okay, so let's go into our game and we are going to test this out. We open up the battle. And the, By the way, we can also create some kind of have some kind of music play differently when we enter a battle. So let's try to go to the next term, 1, 2, and now keep track of the current term. So when we had the three, we waited a bit, 1, 2, working also something went wrong as double-click must not be negative. Okay, So index out of range, index must non-negative and less than the size of the parameter. Can I please know? Where do you mean? Oh, okay, so I know what the problem is. The problem was in here. So we create a list, it's empty, and then we try to go through a range in the count. This is a big no-no. So what we need to do is put it down here. And now when we run our game, we don't have this problem anymore. Run the game, hit the geeky. And now you can see, so turn a 0, we increase it by 1, 2, 3, it goes out, look for, and then back to 0. How cool is that? So now we are back waiting for their turn, so waiting for us to play. So I hope you enjoyed and I hope you create the coroutine. It wasn't too hard. I hope all of this code isn't too confusing. If it is, I do recommend the true look back on a check every single line, make sure you understand what is happening because as we move forward, things are going to get more and more complex. This is very important to understand what is happening. Why are we calling certain things and certain positions? Why are we calling this end here? Well, because this is the perfect place to call it, we can immediately start the coroutine as soon as the button is deactivated. So I'll see you in the next video where we actually understand where the enemy is attacking by creating effects on top of the players that are getting attacked. So I'll see you there.
99. Attack Effects: Welcome back my fellow game developers. And in this video we are going to be creating some attack effects. So we have the lightening, we have the blue fire, and we have a slash. Yep, Those are the attacks I'm going to create the rest. I will leave you to find your own attack. Fats, create all of them, and let's not waste any more time. All of these are available on open game art and let's get started. Okay, so now our enemies are attacking. They are picking which player they want to attack. But there is no effect, and we need some kind of effect to make our game good. So let's go ahead and create a couple of effects. So we can see right here and the enemies characters, sprites that we already have this major bullet and this tentacles that we can use and the fireballs are especially nice. So I'm going to use these and I'm also going to go into the sprites and create a new folder in here. This is going to be the attack effects. And I've provided you with a couple of attack effects as always, these are all from open game art, so I'm going to add this one in here. This is for the regular slash, for the regular attack. Then we have the sparkling fireball back, and we're going to use this one. Let's add it in here. It's a bit big. So we can say that this is lightning because we already have maybe fire or we can use different effects will have I think fire. Let's see. What do we have in here. So the characters, let me take everything out. So this one fire and this one is fire. So we can use those. If you want. You can create a tax for the enemies separately and 40 players separately. I think that we can use both may be some special ones like the mage or the tentacles can be used just for the enemies and the other ones can be intertwined. You know what I mean? So let's go ahead and move those to the sprites of the attack fact. So there we go. In here we have these fireballs. We're going to put them all on a single line to create an animation. So let's go ahead and do that. And if I put this, oops, let's go to the scene. And those look like on the player. Let's add this in here. And it's, let's make it the background. And it's a bit small. So I'm going to choose all of these and make them 32. Let's see how big that is. Yeah, that's big enough, I think. Now let's go ahead and create an animation. So we'll go into our window. Or we're going to create a empty game object in here. Or, you know, let's keep this slash animation. Or just slash whatever you want. It's on the background, it should be on the battle background or battle character, battle character one. Save that because we want these attacks to be on top of the characters. Okay? So we're going to go to the Window, go to the animations. Animations will docket next to our game. And here we're going to click on this one, click on Create. If we go to the Assets animations, spent a while since we went to the animations. Animations, you should probably do your homework right now. So slash and make sure you remember how animations work. So we're creating a slash animation. We're going to select all of these and we're going to drag them in here. So now when we run it, yep, there we go. This is our animation. Maybe make it a bit slower. So let's see. Yeah, I think this is good enough now there are many others that you can add. So in here you can see that besides the fireball and the everything there is those alternatives, different colors, different types of slashes. There's the classic, I'm using the classic. There is this one and those one and the others use whichever one you find suits you. This is purely for demonstration and I think it's a good enough example. But there is one more thing that we want to do, and that is at the end you can see in here. So this first 1, second, 1 third, fourth, and the fifth. And then I want to turn it off. So at this point, I want to hit the Record button and I want the sprite renderer on this slash to be turned off. So how does this look? So when we run our game, as you can see at the end, it gets turned off and then we will start all over again. There we go. And now we can also go to the animations and I want to make sure that it's not looping. So the slash does not loop, save that. It runs. There we go, and it turns off at the end. There we go. Okay, great. Now the next thing to do is we want to add a script to these attacks. So we're going to go into the scripts. And I just noticed how much we've already done that, so amazing. So when the battle system, we're going to create a C-sharp script called Tech fact. I mean, do you remember when we only had a couple of folders? Only a couple of folders, a couple of C Sharp scripts. Now look how much we have and how much we've organized and also how much we've added to the masters. I mean, look how much we need to scroll down. I feel very proud of myself and the view of course. But anyways, let's get back to business. We are going to attach the attack, affect the animation slash. We're going to double-click. And then here we are going to do a couple of things. So we're going to serialize a field, and this will be the, a float which is going to be the effect time. So how much time there is and when we destroy it. So we don't want to keep the animation in there. We want to destroy it after the effect time is done. This will be unique to each of the animations. Then we are going to add another serialized field 40 sound effect to play. So when teacher as affects number to play, because of course, each animation will require some kind of sound effect. And in the start we are going to access the audio manager Door instance. The lay as affects the S f x number to play. And I don't think we have sound effects for all the attacks. I'm sure you will find all of them. Then we are going to go and update. And we're going to destroy the game object, but not just destroy it, we are going to hit a comma. And you'll see that if we add a T, it's an optional amount of time to delay before destroying the game object, and it's going to be the effect time. So why are we doing this? Because we don't want the slash game object to stay hanging around. We want to instantiate it, turn it off at some point after we finished. So I'm going to move this to 25 in here. And I think we want to just keep it the effect time. How much is this? How do we know amature? 25. So 30 is the middle, so this is 1234. I don't know. Let's just keep it for, I don't know, 0.5 seconds. That's, I think 30. So this is 1 second to 35 and this is a bit less. And this is the slash attack. Do we have any slash attacks and the AudioManager sound effects? Let's see the scar dialogue monsters, spell. Check. I think we should want, let's use the dialogue for now. What's the dialogue? So we can play it in here. So this is the attack modifier, which is very nice, dispel attack, which is very nice. We'll use it for the mage. I feel it's scarier. But as this, this is the monster. We can use it. And the area transition, we can use it. And I'm going to use the dialogue or the slash attack. How convenient you can go to Open game ofs and download your own. Please do, don't use what I'm doing. I'm an elite school TUV. Whereas the background sound effects, dialogue too. So it's element to slash, to save that. Okay, great. Now I'm going to issue a challenge. And that challenge is to go ahead and create all the other effects. So set all the other effects that you might want to add to the attack. And that's it. That's all that you need to do in this challenge. The fire, the spells, the major attacks, whatever you want, create as many spouse as you want. And pause the video right now, go to the challenge. Okay, welcome back. So now that we have the slash effect, we are going to go to the prefabs. And remember what I said, how happy I am. I'm getting a bit annoyed. We're going to create a new folder in here for the tech facts. And we should probably also manage all of these, but not now, we're going to add the slash. Let's just call it the slash without animation, so slash. And now we're going to create a, another effect. So we're going to go to the sprites near. And the attack facts, and let's see what we have. Let's double-click. This is the one that we've just done. So the attack facts, let's do the fireball multiple ply Sprite Editor. And let's see how we should be slicing this up. 64 is too big. 32 by 32 slices up. There we go, apply. Now we have our firewalls. We are going to make sure that it's a filter. No point gives us better quality. We're going to drag this one in here. It's very small. And we are going to set it on the battle characters one. And turn. Blue for ball, blue, ball. Hit Enter. Let's make this one bigger. So I think this one needs 16. Apply. Yep, there we go. This is 16. We're going to add a, what was it called? The it was called the F attack effects. Oh, yes, attack effect. And let's create an animation. Where did you go? I animations, attack animations. Blue, fireball. Save that. Jag. These. Put them in here. Let's run it too fast. 20, slow 15. Yep, there we go. I think this is enough. And on the last one, so We're going 5555, we access the game object and we turn off the sprite. And we're going to set the effect time to be 0.4 seconds, and the effect to play will be the AudioManager, fire fact four. So four, save that. And o prefab everything at the end. What else do we have? This one? And here this is the, let's call it the sparkle or lightening multiple ply Sprite Editor slice. This one is a big image you can see right here. So I think we need the 256 by 256 slice that up. Yep, there we go. Nice guess. And we're going to add this park right here. I'll put it in here. Where's the fireball? Oh, wait. Did we do something wrong? Yep. We turned off the sprite without without actually hitting the record. Turn that off and save that stop run. So turn off at the end. Okay, Excellent. So the last frame turns off. We need to make sure that all the animations will not loop. So the sparkle fire battle background, one, 32. Yep, there we go. That's a nice lightning effect. So lightning effect. We're going to create the animation. Lightning while lightening effect. Let's just keep it at lightning. Will choose all of these and drag them in here. So let's see. Is it able to first, let's make them 1 second. Yep, there we go. I think this is a nice one. I'm going to add the attack affect. The attack affect time will be 1 to the audio, will sound the fire also. What was the fire for? Isn't it? Yeah, for four and on the last one, which is about here, up here, around here, and we run turns off. Stop Recording, save that. So it turns off on the last one. Let's put it back here. So now we have the lightening effect. What else should we be adding? The tentacles? So we know there are a couple of more that we want to add. Each will have their own effect time, each will have their sound effect play. I'm going to do them offscreen just to not waste any more time. And I'll see you in the next one when we actually start using them on players. So I'll see you then.
100. Selecting Attacks: Welcome back, my fellow game developers. In this video, we've actually made a lot of tax that actually work. So when we had the beekeeper, we start the battle. We had the N and the enemies attack. There we go. So as you saw, they choose random players. So each of the enemy's shoes, random players and choose random attacks. So let's try this one more time. Yep, there we go. Random player. A random player. Let's try this again. There we go, The Lightning, how cool is that? So we are using the slash, the lightening, the purple attacks. It's so amazing. It's so cool. We are choosing random players. It's very fun. So let's not waste anymore time. This video is long enough and let's get started. The animations all have a loop time of 0 or I unchecked the loop time. So now we can go ahead and delete all of them. We're going to save all of this. And then we are going to go ahead and create a new script that's called the battle moves. So in our scripts, in the battle section and battle system, we're going to create a C-sharp script. Battle, moves, hit, Enter, wait for it to compile. And this is going to be a very special kind of class because we haven't done one of these yet. We are going to remove the morning behavior. So you'll see right now that update and start can no longer abused. They are regular functions and we are going to be deleting them. Why are we doing this? Because we don't want to actually attach but moves to anything. We simply want to keep it as a source of information. It's kind of like the items assets that we've created. So somewhere in here, the items Assets, you can see, although we have the start in here, so it's kind of different, but battle moves won't be attached to anything. It will just be used in order to, uh, to do a couple of things. And we are going to add in here that it's a system dot serializable. And this will indicate that we can use it anywhere. So we're going to create a public String Move attack. We are going to duplicate this four times because we will have four types of variables. And here we are going to have an integer for the MOOC power. We are going to have an integer for the mana cost. Because remember all of these are spells that have mono, not the attack though we'll set that to be 0. And finally, we will have in here the effect that we want to use. So battle effect, where is it? Battle, battle, battle. Battle moves that we call it moves or battle effect? No, there we go. There it is battling fact. So public battle effect or a tag fact. Sorry for that. Oh my God. Okay, So the effect to use, and we're going to be adding it. Now let's go back into the battle manager. So where's the battle manager? Where did it go? Seriously? Where did it go? So, but Manager, here we are for some reason with close down this. So we're going to most of the math again and they start, but also. And in here we are going to create a serialized field, which is going to be the battle moves. And it's going to be a battle moves list. There we go. Now, if we go into Unity, go to the battle manager. You can see right now that the battle moves when we click on them. When we add an element, this element has multiple a variables inside of it already waiting for us to add. So we're going to do just that, will lock this down. We'll go into the Prefabs. The attack moves, and we're going to go ahead and add the blue fire. So this will be the blue fireball, the move power, let's say it's 15. I'm not even sure what these numbers are going to be. These need to take a lot of time and make sure that all of them are correct. So we have six. So the laser Move power, let's say it's ten, mana cost is six. And I think manacles should be much more. So mana cost will be 100. And the blue fireball, the mana costs should be 200. The heavy go. The blue fireball. Let's see, we have the lightening. And I think I've written lightning wrong. And the attack will be, let's say 25. And the mana cost will be 120. And these are very weird numbers. I'm not sure if they are going to be any good when we actually try to use them. And I'm going to add the slash and the tentacles. And we're going to add in here purple. So the purple tentacles will have an attack power. All I'm really doing all of this off the top of my head. A cost of 300, the slash a more, let's say 10 and amount of cost of 0. And the move of the tentacles will have a move power of six with a mana cost of 360. Okay, great, so now we have all of our attacks set up properly. Let's save that. So now what we'll do is instead of simply removing ten health from the selected player and the enemy attack, we are actually going to access our active character on the current turn will generate a random attack that the actual enemy has. So if we go to one of the enemies prefabs and here you can see that we have the attacks available. So now we can like the elements and add the names of the attacks that we have available. Choose one of them to attack the enemy, to attack the player with, and it will choose randomly. So let's go. First of all, we are going to create the code for this. We're going to go back into our scripts and on the enemy attack. After we've selected a certain player, we are going to create another integer in here and it's going to be the selected attack. And it's going to be a random dot range. And it's going to be between 0 because we start off at 00 and active characters at the current turn, we are looping because we want the current active character, so the current enemy that we are using and we are going to access the attack moves. So attack moves available is not access to us because that's go to the battle characters in here, we want to return. So we're going to create a method, a public string array called the attack moles failable. And in here we are simply going to return the attack moves available. Let's go back into the battle manager. So attack moves available, the length. So it's going to choose between 0 and the number of attacks moved that we have. Then we are going to create a loop. So we are going to be looping through the battle moves list. So when I equals 0, I is less than the battle moves list that we just created. Length I plus, plus. And then in here we are going to check if the battle moves less at the position I dot moves name would be not add a move name. So this is the Move name. Why did I call it move attack? I don't know move name and this is going to be the moon. Move name. Thank you. So I'm a bit off my game. No worries about that. Michael, come on, concentrate. We are going to access the active character on the current, current turn with the attack move available. So I'm going to copy this line. Paste it in here, and at what position are we going to access this? It's going to be at the selected attack. So if there is a similarity between them, so we are looking for the random attack that we got from these randomly selected attack, and then we are comparing it. Do we have that battle move inside of our battle manager? If yes, then we are going to instantiate. And we'll open this up. We don't need to assign it to any variable. And we are going to access the battle moves list at position I dot the effect to use common. This will be the object. Now the position and rotation active character v Selected Player to attack the transform the position and transform the rotation. So this will find, and we don't want to add any parent, we really don't need to. So what is going on in here? We are randomly selecting a player. We are randomly selecting an attack. We are looping through all the available attacks that we can have. We are checking if we have the attack and the battle moves attack when we do find it, then we instantiate that effect on the position of the player with his rotation. So let's save all of that. Let's go back into Unity. And we are using the warlords and the main page when we start a battle. Let me just double check that we are yep. Oh, the master mage. So the major master, master my age. Okay. So what kind of moves does the master mmh have? We are going to go to the Prefabs attack effects. So what do you think a master has locked down? I think he has tentacles. He has the lightning and the he probably also has the laser. So because he's a master image, I'm going to look how much heme has mono and I think the purple is also something that he has, the purple tentacles. Okay, so we are going to save that. And then we are going to choose another Butler, the enemy, The Warlocks. We're going to lock them down. And the more luck should have a little bit less of a tax. So the prefabs, he'll have the blue far, but of course, he doesn't have the lightning, doesn't have the laser, you'll have the tentacles. And let's say he also has the slash, copy that paste it in here. So he has also the slash even though I think we don't need the sludge, let's keep it in here. We'll save that and let's go ahead and test out our battles. So we're going to run the game. We're going to start a battle. We are going to go to the battle manager so we can see what's happening in here. Close this down. So we hit the N key ones to three. Okay, so nothing is happening. Oh, case. So the problem is that when we changed from move attack for some reason because of my lack of concentration, I named this variable in here and start off moved name, move attack. So we changed the name of the variable and by changing the name of the variable, we deleted the name in here. So when we are searching and the battle manager and here, so the battle move name, is it equal to any of the available? Of course not because the available are all, or the battle moves dot name are all empty strings. So we need to do this all over again. And let's go to the prefabs and copy and paste all of that. So the attack moves. Let's go to the manager, will lock this down. Blue fireball, the laser, the lightening. We need to make sure that they are exactly the same. Otherwise it will not find them. As you know, we are working using string references. Save that and now I am almost 100% sure there. So I wanted to tell you how I actually debug this. So I had a printed here and I went through. So I just wanted to make sure if we aren't getting to this point and here. So I added a print. I saw that yes, we are actually going into the loop. So I added a second print in here that we are instantiating or instantiate. It doesn't matter whatever suits your needs. So I saw that we are not actually entering into this if condition. So then I immediately knew that the condition in here is not being met. Why? I looked around and I noticed that they were empty. So this is a small pro tip for you. Now we should have everything running smoothly. So run our game. The beak is something is out of ordering here. Double-click, What's the problem? Will try to move past three hip the LIGO, the Laser. Yep, there we go. And they both attacked the skeleton. So nice. As you can see, everything is working correctly with its sound effects. There is a bit of a problem in here. As soon as we start the game on the wakeup. I think this is nothing too scary. Yeah, I think most probably this is nothing too scary. So I hope you enjoyed this video. I hope you enjoy seeing the mistakes that your instructor makes, the lack of concentration and where it can lead you while game developing. So if you are enjoying the scores, you know the drill, leave me a review. It helps me out a lot. And I'll see you in the next video where we actually start attacking with our players.
101. Section 15: Damage Amount: Welcome back, My favorite game developers. In this video, we are actually going to be adding damage from the enemies to the players. So when we run our game, hit the B key, go to the enemy Stearns. There we go, One attack, attacks. And you can see in here that we've actually had a critical hit. So instead of 127, we have 254. And you can see in here all the damage who was dealing good. So first of all, we had the master who dealt 127 and then the warlord 93. But instead, because they had critical hits, they are doubled. So let's not waste any more time and let's get started. Oh, okay, So now before we move to players attacking, we need to establish damage control. So we need to make sure that we have a way of applying damage from the enemy, from the player, and so on. So how is actually damaged cock to work? Let me just show you and talk a little bit about calculating the damage amount. We have two variables for the damage. We have the dexterity and we have the weapons, powers, steep weapon that we pick up. It has some kind of attributes. We can use it with the dexterity that is already available on the player, which increases each level. Then we also have two variables for the difference. We have the defense, which is on every single player. It could be the skin that he has, the clothes that he wears, the type of build that he has, et cetera. And we have the armor defense, so it's the armor that he picks up. How good is the difference on that, et cetera. Do not complicate things, will just add the power and the difference. We won't be going too much into it. So the damage amount will be the power divided by the difference times the MOOC powered. So because we've said that each spell or slash or whatever it is, we'll have a certain moves power. So we are adding this into account, and then we'll just add some kind of random constant. And finally, we'll also add a small amount of critical damage with a certain percentage of working. So let's go ahead and do that. So we're going to go into the battle manager. Let's open up the scripts and we're going to create a method to deal damage. So I'm going to close the enemy. Look how big our method has already got. I mean, our script has already got. So in here I'm going to create a private void, deal damage to characters. And this is going to be used both on the enemy or used by the enemy and the players. So we are going to first of all get a parameter which is going to be the selected character to attack. So this will give us the enemy that we actually already player that we actually need to attack. And another integer which is going to be the move power. So how much power does the move that we're using to deal damage to a certain character actually is. So now we're going to first of all calculate the attack power. So we're going to go float attack power. And it's going to be equal to the active characters, which is on the current turn, dexterity. So we're taking into account the dexterity. Then we are also taking a county weapons power that he has. So active character, current term dot weapon power. Save that. Now we are going to calculate the amount. So float the dicey just amount, I meant to say the difference amount. So we're going to calculate the amount of defense that we have. So we're going to check the active characters. But this time we are using the selected character to attack. So we have the act of characters in battle. We are choosing the selected character that we want to attack. So in this place, if we're attacking with a player, then we want to attack an enemy. If we are attacking with the enemy, then we want to attack a player. So we're going to calculate the defense of the player or the character that we want to attack. And we also are going to take into account, I think you already know what we want to take into account. And that is the armor defense that he has on Nope. Armor defense. Okay. So as you can see now we have the attack, we have the power. Now we need to calculate the damage amount. So damage amount, and it's going to be equal to the formula that we established. So it's going to be the attack power divided by the difference amount that we have. We are going to then multiply it by the move power. And we are going to also multiply it by some random range. And in here, it really depends on you. How much randomness do you want to add? I think 0.9 F and 1.1 f is a good amount. So this will give us around either 90 percent or 110%. So this is the basic range of the damage that we do. It's a bit of randomness. It's nice because we take into consideration, for example, let's say the MAE does some kind of magic and doesn't hit the player completely. So it's a nice touch, I think. And you can change the formula if you can find a better formula. This is one of the most basic types of formulas you can also, if you have your own player stats, you can add your own into this. So moving on, what do we want to do now? We want to convert this damage amount into a integer because we have it as a float. So we're going to type in the variable, which is going to be the damage to give. And we're going to convert it into an integer. And why I'm I doing this on a separate line? Because I believe that it's much clearer as we move through. So you understand we are calculating attack, calculating defense, calculating damage amount, and calculating the damage that we want to give. Okay, great. Now because we don't have any way of indicating how we are going to or how much damage we are dealing. We are going to use the debug dot log. So debug dot log. And we want to know which character is dealing the damage. So the act of character on the current term, dot name. And we're going to concatenated and say that he just dealt, dealt, dealt. That's how that's how you write delta, I believe. Yes. And then we are going to concatenate it with the damage amount. And we're also going to actually show how much really the damage is going to have an effect. So I mean, by that, we're going to concatenate also the damage to give. And we are going to close it in-between these two brackets. Okay? And we'll also add in here something more that I almost forgot. And we'll say that in here too. So for example, the dragon just dealt certain amount of damage to. And then we again concatenated with the character or the active characters, the selected character to attack. So now we can see clearly what is the damage, who is dealing it and to whom it's being dealt. Finally, we are going to take damage. Do we have that Method and our characters, the battle characters in here will need to create a take damage. So public, void, take HP damage. And this will be the integer damage to receive. And in here we are going to simply remove the damaged from the current HP. So current HP minus equals the damage to receive. And obviously when the current HB, if the current HB is less than 0, then we are going to set the current HP to be equal to 0. That's it. We save that. I think we have a somewhere to take care of this, but we'll just make sure that we add this condition in here, just in case we don't want to go below 0 with our current HP. So finally we get the act of characters. We go to the selected character to attack. We take HP damage and the damage that we want to receive as the damage to give, which is an integer because we made sure that the parameter in here is an integer because the current HB is an integer. And finally, we're going to call this method. And where do we call it? Well, we call it after we finished attacking. So in here we'll need to deal damage to the character we need to send to the character that we want to attack. So we already have it in here, the selected player to attack. So select player to attack and what is the move power? Well, we are going to get it in here after we instantiated. So we'll create a variable which is going to be an integer. The move. Power. And let's set it to 0 for now. And after we check, we make sure that the move is available than the most power, there's going to be equal to the battle move list. At the position I dot the move power. We save that. We send the variable in here, we save that. And now let's go ahead and test all of this up. So let's go back into our game. And currently the power or the attack only works on the, using the enemy on the player. So we're going to go ahead and start the battle. And we're going to go to the next turn. And for some reason we don't have the canvas showing. So the battle manager battle scene, the battle canvas. When we run our game, that's just see where the problem is, it the BK, whereas the battle scene, where is the menu? So again, if you ever encounter such a problem where everything is destroyed, we need to go in here and make sure that it's 19 by 20, 1920 by 1080. So now let me turn off this battle scene. There we go. Run the game. Hit the B key. There we go. So let's go to battle manager. That said the N, and now the enemies are attacking. Yep, there we go. So we already lost because we've been killed for some reason. This is not very good. So let me just go back in here in the console, stop the game from running and let's look at what's happening. So the major master dealt 128 to the gram, which is the battle character. And then the Warlocks del 251 to Draco. Okay, so and then we lost. Obviously we still had one of them available. There's something a bit wrong, we'll fix that later on, but for now we are dealing damage was just very good. So the next thing to do is to go ahead and add some kind of critical damage. So in battle manager, we are going to close down the update battle. We need to go back and check why we just died like that. We need to create now a bit of damage or critical damage calculations. And it's going to be part of your challenge. Your challenge is to create critical damage. You'll need to create a method that returns an end to calculate the critical damage with an argument, you will need to use the random dot value inside of an if statement and return the damaged value times 2. So the critical damage is a damage that is times 2. Finally print out the amount and the debug dot log and you'll need to, of course, call it from deal damage and assign it to a variable. So pause the video right now and go create a critical damage method. Okay, so first off, where do we calculate the damage? Well, and here we see that we have the damaged to give. We can actually under it, go ahead and say that the damage to give is going to be equal to calculate Critical. And we are going to give it the damage to give. Now let's go ahead and create this method. So we'll generate the method. And in here, what we'll do is we are going to create this f, which is going to go to a random value. And you can see that this returns a random value between 01. So this will give us, if you want a certain percentage and if it's less than, let's say 0.1 f. So we have a 10 percent chance of this working. We are going to use the debug dot log o'clock. And we're going to say in here, career tickle hit. Instead of damage to give points. How many points or how many damage points that we are dealing? We have dealt damage to give times 2. And just hit the Enter key in here and then start concatenating again. Was that There we go. So critical damage instead of the regular damage to give or points, the damage to give times 2 was dealt. And we are going to return damage to give times 0 times to save that. And let's just put these in between brackets just because 44 to make sure that it works. Else, if it doesn't work, then we are simply going to return the damage to give. So what's happening in here is we are checking. We are getting a random value. And if that value is less than 0.1, random dot value gives us, as we've said, a number between 01. So if it's less than 0.1, that means it has a 10 percent chance of working, then we are going to return the damage to give times 2, and we're going to assign it in here to the damage to give. Else. If it's not less than 0.1, then it will simply return the damage to give. And for the sake of testing, we are going to set this to less than 0.8. This gives us an 80 percent chance. And we'll say in here, this needs to change to a zero-point 1 f. Save that. Let's go back and our game. Let's run the game. Let's hit the B key that's at the end. And okay, so there we go. So critical hit, we've just got a critical head. So instead of 211 points, 422, was that okay? Very good. So I hope you enjoyed I hope you're understanding how everything is working and I'll see you in the next video. We also dealt a critical hit in here. So I'll see you in the next video.
102. Which Enemy Is Attacking: Welcome back, my fellow game developers. In this video, we are going to learn about particle systems and we're going to actually use them. So when we run our game, remember when one of the enemies attacked and we didn't know which one is attacking. Of course, using the console we could have known, but visually, how do we know? Well, as you can see, now we know the enemy that is attacking has this little glow of red around them. It's not perfect. It's nice enough and it gives us a way to know. So for example, the major attacked first than the war lacked attack second. So let's not waste any more time. Commit your changes at the end of this video and let's get started. Oh, okay, welcome back. So we died previously, if you remember in the previous video too fast or we lost too fast, That's because the player, Jimmy has a current HP of 0, so we're going to set it to 100. And also the skeleton dice and one hit. So maybe we should increase those to maybe 200 by 200. And we do that for the gram also. So we're going to set this to two hundred, two hundred, save that, apply the changes. And that's all that we need to do. So let's save that and let's get back to the real problem in here. And that is that we don't actually see visually which enemy is attacking our player. How are we going to know that? Well, there is a very simple way and that is to create maybe a small circle or Spark or maybe some kind of folk around the enemy that just attacked one of the players. How are we going to do this? Well, we are going to use the Unity's particle system to create an effect. I'm not going to go too deep into particle systems because they can be a course on their own. I'm just going to go over the basics and show you a predetermined particle system that are not necessarily created, but got the idea from. So I'm going to right-click in here. I'm going to go to wear resistant to the effects and to the particle system. There we go. So as you can see, we already have a particle system will set the position of the set to 0. And if we unclick the 2D, you can see that these are our particles and I'm going to move them to the front. So there you go. You can see now that we have these particles coming out, let me just move them more and there you go. So I'm going to make this bigger and we are going to take a look at these particles. So as you can see, they are not rendered in front because they're sorting layer is different. Rendered we can choose which sort layer they are on. So sorting layer, let's put them on the battle characters and order layer one so we can see them clearly. So as you can see, these are our particles. And the way they work is as we move around, you can see that these are 2D small images that always face the way we are looking, whether it be in the Scene mode or on the game mood. And that is because they want to save a bit of memory and space and rendering so many particles is very, very confusing and heart. So let's go ahead into the inspector and do a couple of things. As you can see, there are hundreds and hundreds of things that you can change the knee from noise to external forces to rotation of speed and all of those. And as I've said, I'm not going to go into every single one of them, but I'm going to try and explain the things that we are going to do. So first thing first is we are going to make this an emission of burst. So in here we can add the burst. You can see the emission over rate. You can see we can decrease it, increase it and so on. I'm going to add a burst. I'm going to go to the shapes and make it a circle so we can change shapes to a sphere, for example, I'm going to make it a circle. I'm going to of course try to rotate it. No ports that prints Warm, Don't need that for now. I'm going to rotate it. So there we go or we can put it to 0. So now it's kind of bursting as you can see. When we see it in just a bit. Yep, there we go. That's the burst. We can change the burst of the cycles and the counts. Let's turn out the rate over time. Now we can see a burst. There we go. The probability, the interval can be maybe one. And it doesn't really matter because we are going to make it just appear once and then disappear. We don't want to be all the time. We can add 60 particles and so on. We'll see later on how all of this is going to change. So 60, circle 60, the burst, and then we're going to go over to the size over lifetime. So in here we have an option. Which is the size over lifetime. Make sure to turn this checkbox on and this will determine what the size is over the lifetime. We can click on the graph right here. And we can move this particle system. And here we have this option. When we click the graph, we can choose what the size over lifetime as we can decrease it, increase it, make the y bigger or smaller, as you can see as they are moving. And this is the speed at which they changed the size. So if we put four here, for example, There we go. If we increase it, they take time until they become smaller. But what we're going to do is we'll just make it. So. So there we go. They start off at one very big and then they get smaller and smaller until they get to around 0 at the one minute. Yeah, there we go. I think this is good enough. I'm going to close this down. Next thing we are going to set the duration. So in here we have options that are very, very small. So the duration in here we wanted to less just one minute. So there we go. Now we have a kind of a batter burst. Then we need to set the start lifetime. So we're going to set the start lifetime to two. And there we go, you can see that they disappear more quickly. We need to set the start speed. We're going to maybe set it to 0 that C. So as you can see, that becomes sort of a puff of smoke. And when we set it to 0, you'll see that it just happens on the position that we want. We don't want it to burst all over the place. When one of the character does something, we're going to add a stop action to destroy. So in here we have the stop action and this is going to be destroyed. This will destroy the entire object because we don't want to keep it and always have it repeating and repeating over the player that are the enemy that just did the move or something. And finally, you can change the colors. So we can set it to red, for example, if you want or kind of an orangey feel, maybe reddish. And I do recommend that shoe pause right now and go look through your entire particle system. There are so many things to play around with and have fun with. There are the lights, the collision noise. There's so many. The color over lifetime is one of my favorite. You can change the colors over the lifetime between two values, for example, which is very, very nice and really could be helpful in this case, I do. If you want, you can also create one of those particle systems and send them to me using the videos on Google Drive. I would love, love, love to see what you come up with because I'm not a very creative person. I just do stop that work and then I leave the creative parts to the people that know how to do that. So I recommend that you really go out of your way. Take your time if you are at rate of person and create something really nice-looking. But for now I think this puff of smoke, read puff of smoke is enough for me for now for us to demonstrate how this will work. I'm going to change this, will just keep it at the particle system name or maybe name it to the character. Attacking particles. Now we are going to prefab it. So we'll go into the Prefabs. Let's make this a bit bigger. The attack facts, and we'll add it in here and the attack facts, we'll save that. And I'm going to issue you a challenge and that is to instantiate the particles. So you'll need to get a reference to the particle system. Use the proper variable that's for you to figure out. Then you'll need to instantiate it before dealing damage. And I'll give you a couple of hints. Position and or if you want to do this on your own, forgot about it. Anyway, position and transform should be that of the active character on the current term. So this particle system indicates which character is attacking, so we need it instantiation to beyond that character. If you want a bit of a refresher on instantiation, go look for it in the unity dogs with that said, pause the video right now and go do the challenge. Okay, welcome back. So we're going to scroll up here. We are going to create a serialized field which is going to be of type particle system. And it's going to be the attack fact or the character fact. We are going to scroll down and the enemy attack in here. By the way, there are a couple of things that we can actually refactor and here, so for example, the choosing of the move and the selecting of the character are very important to become, or we can keep it as a single method. Do you want your game your time to create your own code? And in here we are going to go ahead and instantiate. And instantiate the attack or the character attack effect. We are going to instantiate it on the act of character current, turn the transform, that position. And the act of characters current turn the transform rotation. And we don't need to make a child of anything. This is just good enough. And we'll say here, instantiating the fact. Tacking character. Save that. Back in our game, we are going to delete this. And before we, okay, we deleted and then we'll go to the character in here that's receptive positions in here to 0. Whereas the battle manager, the fact, there we go, we save that. We run our game. We made it seem bigger. We start the battle. And let's go ahead and hit the Anki. Anki. Anki. Yep, There we go. But as you can see, keeps looping and looping and looping and looping. So what's the problem in here? So I'm going to go into the character and see what the problem is. Well, looping, save that, run our game, hit the B key. How cool does that look? From the 3D perspective? It's nice. And attacks. And it goes away. And you can see the enemy attacking particle. It gets South destroyed after 1 second. So now we know which character is attacking. Again. It's the priest or the mange, and then the war lock again. So as you can see, because we've made the Jimmy have current HP, he is not doing immediately. He is actually also getting attacked. And there we go. So I hope you enjoyed the particle system entry. If you want a next structure challenge, I recommend that you go ahead and extract all of these into separate methods. It's really fun. It gives you a sense of how everything works and gives you some organizational subconscious. I don't know what it does anyways, I hope you enjoy it and I'll see you in the next video.
103. Visualizing Damage Amount: Welcome back, My favorite game developers. In this video, when we run our game, we can start the battle. We can. There we go. So as you saw right now, we, not only do we know which layer is being attacked, not only do we know which enemy is attacking, we also know the amount of damage that's being dealt to the character that's being attacked. So I'll show you again. 109 damage has been dealt, 73 damage has been done. And we can confirm that from the console right here. So we don't need any debug dot log anymore. Somewhere in here. We'll delete it later on. But for now, let's not waste any more time and let's get started. O k. So now that we are visualizing which enemy is attacking, the next step is to visualize the amount of damage that is being dealt. So to do that, we are going to create a small canvas. We will have a text on it. And we are going to prefer bit. And every time that we get damaged from a player or an enemy, we are going to create this text instantiated in the air at a bit of jitter and movement upwards and then make it disappear. So let's go ahead and do that. The first thing that we need to do is to create a canvas. So I'll right-click UI canvas and we're going to call it the damage taken. How are we going to make it small? We're going to go to the Canvas and we're going to shoes world space. And this way we can make it as small as we want. Make sure that you change the damage in here, not the damage. I mean, the canvas of the damage taken. Let me call this the damaged thinking Canvas. And we are going to scale it down to 0.010.01. Let's double-click on here, or that's what, move it down next to the players. Double-click on it again. Move up, pivot. There we go. So this will be our canvas. We can even make it smaller. But for now, let's go ahead and add a text. What I'm not going to add the text Mesh Pro because these are going to be numbers. So a regular text I think was phi's. And we are going to write in here 99. We are going to know what, Let's add the text much probe. Why should we not give up, not give ourselves the chance of using the text Mesh Pro? We're going to set it to the medieval party if it lets us. And we are going to anchor to all the corners. So hold down Alt, click on this one, and there we go. So now it's anchored to all sides. What does the damage texting year. I cannot see it. Should I make it bigger or smaller? It's not showing bold. Also may be because let me just see what's going on. Move it in here is the problem. Okay, so there we go. So behind this we are not seeing it. Why is that? Because we need to make sure that we are on the correct sorting layer. So sorting layer battle characters. One, okay, great. So damage taken. There it goes. So over the players, it should appear over the players. We are going to make it a bit smaller. So I'm going to choose the Canvas, go to the ROC tools and make it big. And then we are going to make the font a bit smaller also. So I think this is enough. We are going to also scale it down to be almost the exact size that we needed to be. We're going to change it to red. And I think that's it. That's all that we need to do. It's pretty simple. We're not going to do too much of it. And then we are going to drag it and prefer bit. And now we have this damage amount, so it will appear on top of the player and then go away. We are going to delete this and we're going to create a new script to control all of the jittering and the disappearing and the moving and so on. So in the scripts, in the battle system, right-click create a new C-sharp script which is going to be the character health or the character damage. Gui, GUI, graphical user interface. Even though it's not that. Interface, but it will do the job. And we are going to have, we should have added to the Prefabs, no worries about that. Whereas the prefabs attack, damage, taking canvas, add a component which is going to be the character GUI, character damaging GUI, save that. Close all this down, double-click, open up the scripts. Okay, so what do we need in here? First of all, we need a reference to the text, so we'll need the to be using the TMP Pro. And here we are going to create a serialized field which is going to be the text mesh pero Gui, the damage tax. Then we're going to create a float which will represent the lifetime. And we'll set it to 1.5. We are going to create another float for the movement speed. So move speed. And finally we are going to create texts vibration. So text vibration. And you'll see how we're going to apply this in just a bit and we'll set it to 0.5. These are values that I've already tried and thought of, and we'll set the move speed also to be one. Save that. Okay, great. Now an update, we are going to destroy the game object after a certain lifetime. So destroy game object after the lifetime has ended. And also we are going to access the position and change it throughout the movement speed. So transform the position is equal to a new vector 3. And I'm sorry, I didn't mean equal. It should be plus equal. Why is that? Well, because let me explain. We are going to instantiate it. Then. We want to slowly move it upward. So we are adding slowly movement using the movement speed and only on the zed axis. So in here we are going to set the X movement to 0. And the y movement will be the move speed dot Time.deltaTime or times Time.deltaTime. What is Time.deltaTime? Well, it's something that just, and if you noticed, sorry I'm interrupting myself. These at 0. That's why we didn't need to add a z-component. Anyways, the movement speed times Time.deltaTime. We are, whenever we are dealing with an object, moving an update, or whenever we are dealing with anything that's increasing over time, we need to make sure to multiply it by Time.deltaTime. And what this allows us to do, it separates the frames per second on our game from the movement speed. Why is this important? Because an update we are calling it every single frame when it comes to calling methods and doing things, it's okay when it comes to taking input, it's no problem. But when it comes to movement, if we have a very strong computer and fast frames per second, then the movement speed will be very, very fast. And we don't want that. So what we do, and the opposite is true. If we have a slow PCI, the frame rate is very low and the movement speed is very slow. So what we do is we multiply it by Time.deltaTime. And this detaches the frame rate from the amount or from V times this updates and Time.deltaTime is actually the time between each frame and you can see it and hear the completion time in seconds since the last frame. So this allows us to have smooth movement despite how many frames that we have an hour. Again, this is a very important component, especially when it comes to 3D gaming. And finally, we are going to create a public void, set damage. And it's going to take a parameter in here which is going to be the damage amount or the damage to display or whatever. So we're going to access the damage text. Damage text. The text is equal to the damage amount dot toString because this is an integer, so we need to convert it. Then we are going to create a jitter amount. And it's going to be a random range. And it's going between the minus taxed vibration and plus text vibration, which are the minimum and the maximum. So it will move between minus 0.50.5 from left to right just a little bit, just to add a bit of fun to it. And finally, the transform.py position is going to be plus equals the new vector 3. And it's going to be. An amount. And this is the value on the x and then the general amount on the y. And we are going to leave it at 0, or we can even remove it and use the one the same way we did it up here. So adding the 0 on the set component, we are going to save that. And if you are still a bit confused, we are accessing the text. We are setting it as the damage amount we are accessing or we are setting a general amount which is going to be between the text vibration minus and positive. And finally, we are adding this amount to the position of our text when it gets instantiated. So now the final thing to do is to actually get a reference to it in the battle manager and use it whenever damage is applied and it's going to be your challenge. Your challenge is to show the damage. So get a reference to the Character health GUI instantiated every time a character takes damage or character damage go in here. Instantiated every time a character takes damage and figure out what the positions and rotations should be. I'm pretty sure you already know how to do that. So pause the video right now and go do the challenge. Okay, welcome back. So in our battle manager up here, we are going to get a reference, a serialized field of type, character damage, GUI, damage, texts will call it simply. And then when we scroll down, when we take the damage so the damage is dealt, we can either call it in the enemy attack or we can call it in here. Let's just call it and the enemy attack. So after we deal the damage to the player, we are going to go into the character at the character damage GUI. It's going to be a character called character damage text. And it's going to be equal to the instantiation. And why are we setting it in a variable? Because just a bit we are going to use the SAT damage method on it. So that's why we need a variable or we can just use it on the instantiated, but this is more clean. So the damage text that we've got a reference up there. And where are we setting it? Well, it's on the active characters, but not on the current term, but on the selected to be attacked. So Selected Player to attack dot transform. Know what I think a better place of adding this? Because we are going to be using it also when the player attacks. So we don't want it to just deal damage when the enemy attacks. We also wanted to do that when any damages. So instead of the selected player, we are going to use the selected character to attack on the transform box position. And finally, active character, me, just duplicate this, this one, rotation. Save that. So again, why did I move this from the enemy attack to the deal damage to character? Because the deal damage to character will also be called by the player. And we want to apply the same damage to the enemies as we do, as you'll see right now to the players. So it's better to use it in a method that is more, let's call it universal and available to both parties. So now we instantiate the text whenever we deal damage on the selected character to attack. So we'll save that. Let's go back into a unity and run this and see what happens. So run our game and we get an error. And unity turns off on its own. Oh, okay, welcome back. I wanted to show you what happens if, in case you get this kind of layout, just go to the layout two-by-three and we are back, baby. And before I forget, this was a problem. This is why it happened to me a couple of videos ago. So again, we need to make sure to set it to 1920. Decided in here will change. Unfortunately, there's nothing you can do about unity crushing. That's why you always save and you always create commitments and repositories. So now let's go into our battle manager. We have the damaged text. We are going to go into the Prefabs and to the battles. And we not prefer bit 0. We did prefab at our scared therefore, But so we're going to take the damage text added in here. There we go, the damage taking Canvas, we'll save that and let's try this out. So we run our game and they now we start the battle. We move through the players. Oh, there we go. So at least it's working. We have the texts working correctly, everything is working. Now the final thing that we forgot to do because I was distracted by explaining, what are we doing. So the character of damage text that said damage. Set. Damage? Yes, please. And what do we send in here? The amount of damage. So the damage to give, save that back in our game, we need to set a reference to the text in here. So how will we do this? Let's double-click and open up the prefab. And we'll drag the text in here to the text. We save that. And the way we opened the prefab, we simply double-click on it. It's no biggie. Go back. Now we have the damaged set, text, damage sat run the game, stops the battle. Yep. There we go. 2159. And is that correct? Let me open up the console so we can see in here the first attack was 21. Yep, it was correct. And the second one was 59. Let's try this again. 63, there we go. 220 or 212. Excellent. Let's try this again. Dominance DLT. Okay, great, So everything is working perfectly fine. There might be a bit of tuning, as I've said, if you want to add a bit of more flavor to the text, add its own font, I think is a great idea. You can do a lot of things. You can change the jitter. Maybe you want to apply it on a slightly varied position, not immediately on top of the player. So I hope you enjoy it. I hope you're committing your changes. And I'm going to see you in the next video.
104. Battle Stats: Welcome back, my fellow game developers. In this video, we run the code, we start a battle, we go to the end, but you'll notice in here that we have the grim Draco and Jimmy and their lives actually deteriorate when they take damage. So you can see their lives going away slowly, but surely. There you go. The Graham dies, Draco dies. Only Jimmy survives. But if Jimmy dies, what will happen? And when Jimi dies, we have lost, oh my God. Let's not waste any more time. And let's get started. Oh, okay. So now we know who's dealing the damage. We know how much damage He's dealing. There is still one small problem, one small itty-bitty problem. When we run our game, we hit the B key and everything seems to be working correctly. But the problem is that we have player name one, player name one. Who is player name one? And why isn't the health being changed? And why do we have so much manner? So it's time to start updating our battles stats. Let's go into our battle manager and do just that. I'm going to close down the deal them as the enemy attack. I'm pretty sure we've done with all of these. If we do need, we will come back to them. But first thing first is we need a reference to the texts. So in here we are going to go ahead and create a serialized field which is going to be of type text Mesh pero Gui. What, what, what do we have? Oh, okay, so using the MPI pero, I was wondering what's the problem. So text mesh per row, you GUI. And we're going to have a, and in here we'll need a slider, but we need to set the UI. So I save that. And let me just adjust this. It was 133, I believe. Okay. So a slider, 14, the layer health slider and player mana slider. Save that. Okay, Great. We'll set everything in the inspector before we forget. So battle manager, battle scene. There's oh no, it was the battle Canvas, the player stats. And let me turn on the battle scene so we can clearly see the player stats. Okay, there we go. So I'm going to open these up. I'm going to go to the battle manager. I'm going to lock it down and the player texts will be chosen and dragged into the places. The health sliders are going to be dragged into the correct places. And the mana is also going to do the same. Save that. There we go. So everything is set up, will close all these down and we're going to turn off the battle scene. Go back and unity, we make sure to save all of that. Oops. Oh, no, no, no, not right now. So at least now you know you have a challenge, but before that we are going to create our update player stats. And if you want, you can pause the video and update them on your own. But we are going to first of all, create a is equal to 0 while I is less than the air. The players names text dot length and then I plus, plus. So we are moving through all the players named taxed. We are checking if the active characters dot count is greater than one, excuse me, dot I. And this, why are we doing this? Because we need to make sure that there is more characters than the player texts that are available. If there is not, that means that we cannot proceed, we cannot update the text. You'll see that this is not very, very important, but it's important for avoiding a couple of errors. So we just check that we have more characters, then we have player text names. So then we are going to check if the active character is a player. Of course, obviously, we need to update the players. And then in here is where the fun stuff begins. So we're going to create a battle character variable, which is going to be the player data. And it's going to be equal to the active character. So we have a reference to him because I'm sure we're going to be using it a lot. Then we are going to access the name text. So player name text at the position I, the text. And it's going to be equal to the player data, the character name. Then we are going to use the sliders. So Player health slider at the position i. We're going to set the max value as we always do to the player data dot max, HP, and the current value. And the value, I mean, and in here the current value of the HB. Let's duplicate these two lines. And we're going to use the slider. And the slider. The max value is the max and the value is the current manner. So we're going to save all of that. And now we are going to go to the challenge, something that surprised. So all you need to do is to make sure that we don't show any information unless we have an active player. So you'll need to create an else statements To else statements to make sure that we don't see any empty spots when we don't have a player active there. So pause the video right now and go do the challenge. Okay, So there are two places that we need to make sure to turn off the game object of the tax. So the first one is in here. We have the active character is player. If it isn't a player than player name, text, dot, dot, game object, that sat active is false. And also if we have more active characters or amine, if we have less act of characters than the amount of tax that we have, then else. We're going to do the same in here. Save, copy this, paste it in here, save that. And now the final thing we need to do is to see where do we call the update player stats. While there are a couple of places first, when we deal damage. So we can do this in the enemy. In here, we are going to update the player stats. Where else should we do it? We can do it when we go to the next turn. So update battle, update, player stats. And we also do this when we start the battle. So when we start the battle, we also update the player stats. And I think that's all that we need to do. So we're going to save all of that. We are going to go into Unity. We are going to wait for the script to assemble. We are going to run the game. We are going to start the battle. And for some reason, I am unable to start the battle. That's because for some reason, Let's try this one more time. Oh, okay. So what the battle manager has been turned off? It should be the battle scene that's turned off. Oh, and we have We have it locked down. So there we go. Nope. I mean, There we go. Okay, now we run the game. That was so weird. So we start the battle and, and, and so we have the grim Draco. Oh my God, How cool is that? Seriously? How cool is that? Let's try this one more time. I'm surprised that it worked from the first step. So Jimmy, Jimmy, Jimmy the grim. Nice. Let's see what happens. Draco down dice. Let's see again. Jimi dies the grim dice and we lose because all of our characters have a current HP of 0. But the next thing that we need to do is handle the dead layers when we update the battle, if you remember, we have killed character in. So I'll see you in the next video and make sure to commit your changes. And if you're enjoying the course and you like me as an instructor, I would love to know your opinion. So leave me a review whenever you can, whenever you want, whenever you feel like it. And I'll see you in the next one. Hey Mike leader from the future. I know you wanted to get rid of me, but here I am back again. There is a small problem. So when we run the game, you can see that we turned off the gram, but we can't only see his name. So this is a small problem and here we are only turning off the player text name. That's not what we want. So what we'll do is we'll get a reference to the players. And here instead of just getting the name, we are going to reference also the game objects. And it's going to be game object. And we'll call it the players stats or the Players Battle stats. We'll save that. It's going to be an array. And we'll use the player battle stats in here. So player stats, position I, and player battles, that's position I. Whereas player battles that. Was that so hard. So we'll save that. We'll go back in here, will need to reference them. Claire battle stats will choose, will lock this down. Choose the player one through three, set them in here on the save that turn off the gram or Draco, we run the game now we shouldn't see it appear. So there we go. We don't see the Grimms entire structure, which is much better. So sorry for interrupting. Maybe you wanted to rest. You were saying finally Michael, It's solver week. Don't need to listen to him anymore, but he comes back. So I'll see you in the next video where we will be killing our characters. Very fun.
105. Handling Dead Battlers: Welcome back, my fellow game developers. In this video, we will be skipping over the players that are that. So currently we need three terms for the players. But when one of them dies, you'll see. So now Draco dies. And you can see right now, determine a 0 when we had the Anki once, it goes immediately to two, so it skips over Draco's turn. It goes immediately to the enemies. Only two terms are taken. So now if we had the Anki ones, we attacked with Jimmy immediately go to the turn of the enemies. So let's not waste any more time and let's get started. Oh, okay. So currently everything seems to be working fine, but there is a small problem. I'm not sure if you've noticed it. If restart the battle, let's say we have jimmy and Draco. We had the Anki and key. There we go. Jimmy. Jericho again, let's try this. So Jimmy Draco. Draco just died. Okay. Dre could just die. That means he doesn't have to get a turn. So now we should, in theory, when we press the Enter key, only have jimmy play and then we move on to the enemies. So we hit the end. We had the n again. So obviously you can see that we took a turn and if it wasn't obviously me turn on the gram. So the problem in here that even though some of our characters are dead or our players are, that they are still taking turns. So in battle manager again, 123, so three of them are attacking. Hopefully one of them dies 3123. We want one of them to die. 2, 3. This is gonna take forever. Okay, so now Draco died 1, 2, 3. Again, we are going through the terms. And there we go. So you can see that the turn is still playing for Draco Jimmy and each player that dice. So this is a problem we don't want to have. So what we'll do is every time we are checking if all the enemies or players are debt, if they are not. So that means we don't either lose the game or when the game. We want to skip over the character Stearns that have a current HP of 0. And we're going to do that using a while loop. So what is a while loop? It's similar to for loops where it executes a block of code a number of times. But instead of determining the number of times before hand, so instead of setting ILS than, let's say the length of an array, we wait until a certain condition is met. So the structure of it, we have a while loop. We have a certain condition that is true. If it is, then we enter into the code and this bracket. And we keep doing this again and again and again and again until finally, we have this condition to be false. And when it becomes false, we stop going through the loop and these two points right here should not be present. Let me just remove them. Welcome to the back-end. There we go. So make sure that you understand how while loops work if you want, go check them out in different places, search for them, make sure that you know what to do because in just a bit, you have a challenge to skip the characters. So an update battle. If now all the enemies are, all the players are dead. After we check if none of them. That's what I mean. So you'll need to add an else statement, will need to create a while loop that keeps looping. While active character HP is 0, increased determined by one when it is. And if the turn is greater than the number of active characters will need to reset it back to 0. It's a bit of a hard challenge, especially because you are using a new weapon that we've just understood, which is the while loop. No worries. Do your best. Pause the video right now, understand the challenge. Understand while loops, and go. Do it. Okay, welcome back. So we're going to move up. Where is our update battle? There we go. So if all the enemies and all the players are dead, we are either going to win or we are going to lose. But if none of them are, then we'll create an else statement will create a while loop, and this will keep looping while the act of characters on the current turn. Dot current, HP is equal to 0. So on the current term, while we have a character that has a current HP of 0, we want to increase the current turn immediately. And we'll check if the current term is greater than or equal to the active characters dot count, then we are going to set the current turn back to 0. And that's it. So what's happening in here? As we are updating the battled, we check if we have now we haven't dealt with killing characters. We'll do that later on, don't worry. So if all the enemies or all the players are in that, that means that we might have one of them that has a current HP 0, but still taking turns. So what do we do? We create a while loop that keeps checking all the characters on the current term. If they have the current HP of 0, then the current term is increased by one. If the current term is greater than the act of character count than the current term is back to 0. Then we look back, we go to the next character because we've increased the turn and this while condition hasn't been met. So we check if the next character also has a current HP of 0, then we move again, enter the condition, enter the while loop. We increase determined, we continue one, then we go back into this while loop. So finally we get to one of the character that doesn't have a current HP 0 and we stop the battle or he does his move or whatever. So we're going to save that. You'll see this in action may be understand it better if you're still confused. Save that, run the game. Hopefully one of the players dies immediately. So and there we go. How cool is that? Draco just died. So now when we hit the End key once, well there we go. So the current term immediately jumps to two. So now we hit it twice. Great. So now Draco doesn't have a turn. So again, we had the Anki once we move immediately to the second, third, jimmy died. So now technically we should only hit the Anki once. Girl rate. So everything is working correctly. Players that are, that are not taking turns. And now I'm going to commit my changes, players and characters, because this will work both ways, no longer take turns when they're committed changes. Go to the master and see how much we've been through. We've been through so much and there is a little bit more to go. So I'll see you in the next video.
106. Section 16: Player Attacking: Welcome back, My favorite game developers. Remember when our enemies used to attack us while we had no way of defending ourselves. But now all of that changes because when we start the battle, we don't just skip our turn. We can actually attack. So we attack will the skeleton, we attack with Draco and we attack was Jimmy. Now we get our asses kicked. I'm not sure I should have. I could have said that. Anyways, you can see that who he are attacking slowly but surely. But we are. So let's not waste any more time. And let's get started. Oh, okay, So now that we have our enemy attacking, we have the battles stats updating themselves. We know which player, which enemy is attacking, which player it is attacking. If the player dies, he can take turns so everything is coming together. But now the next step is boom, make the player start attacking. How are we going to do this? Well, we are going to create another method that allows the player to attack. So let's open up the script. And in the battle manager, as you can see, we have a lot. Now it's time for the player attack. And I'm going to add a comment layer stacking methods. And let's get started. So first of all, I'm going to create a public void player attack. And we're going to give him two variables. The first one is going to be a string move name. So it's the move that we are going to perform and an integer which is the selected, an Emmy. So in here, first of all, it's, it's pretty similar to the enemy attack. It's almost the same. So the first thing that we need in the enemy attack, we get the player. So no need for that. We're going to go ahead and first of all, get the move power and then select a certain move. So in here we are going to create an int mov power equals 0, and we are going to continue. But the difference, or the same thing in here is that we are using basically the same code. What we do is we create the most power. We already have the selected enemy that we want to attack. Then down below in here, we search through the battle most useless. We check if the battles moves. List, dot move is equal to the movie name that we send it through the player attack and so on and so forth. So let me show you, because I feel I've totally botched it. So end I equals 0. While I is less than the battle moves list the length. And I plus plus. So we are looping through the battle moves. Then we check if the battle moves list at position I, that move name is equal to the Move name which is being sent right here. So we open up and then we are going to instantiate the effect, which is pretty much the same as this one. And here we can copy this. We can copy even the move power, copy this, paste it in here. And it's on the selected enemy target and the selected enemy target. Now what we can do in here is we can actually create a method using this. And it's very useful because we can use it in here and in here, which I think is pretty reasonable. So let's go ahead and select these right-click quick action and refactoring. We are going to extract the method. And it takes in the eye and the selected enemy target. So we're going to call this getting more power and instantiating effect. I'm not sure if we should do all of that. And fact instantiation. Oh my goodness, gracious. Case. So getting moved power and effect instantiation. How do you like that? So we're going to use this method in here. So we'll just use the effect instantiation. And what are the variables that it takes in. So it takes in the enemy target, which we'll call the character target. We'll save that. And then we are going to send in here the selected player to attack with the I. Save that and we can remove the instantiation from here. Let's delete it. And of course we are going to be testing this out again. We can actually go and test it out right now. We also have to extract this one because we'll use it in just a bit. You'll see. So there we go. Let's test this out. Make sure that the method that we've extracted still works. So this instantiates the effect of the attacks and they now run the code. So and they now unity is going to start and yet it's still working. Excellent. So we save that. Now we have a method that gets the move power and effect instantiation, getting moved power and effect instantiation. Very subtle. Anyways, let's continue on. What should we be doing next? One, we need to be adding the effects on the attack or on the enemy that's getting attacked. So, and your challenge is to add the effect. So you'll need to call the method that instantiates the effect which tells us which enemy is attacking or which player is attacking. And you'll also need to call the method to deal damage with the appropriate arguments. So with that information, pause the video right now and go do the challenge. Okay, welcome back. How did you get on with that? So we have the most power and here everything should be working fine. So we are going to extract this method from the enemy attack. Well, Right-click. And this is the character attack facts. So this is the particle system, as you can see in here. It's the red shooting stuff. And we're going to extract, it will do an extract method. And this extract method instantiate fact on tacking character. So today is not my best day for giving names to methods, but at least they are really sharp and you know what you are calling. So after we choose which movie are going to do, we add the power to it. We are going to instantiate the effect on the attacking character. And what it does is it chooses the current term, so it chooses the active character on the current turns. So it's going to choose the player which is attacking, which is good. And finally, we need to deal damage. So we're going to deal damage to characters. We're going to choose our target, which is the selected enemy target. And then we are going to give it the move power that we've determined. So let's save that. And we still have the last bit of code, which is to go ahead and do the next term. Save that, back, end our game. And here we're going to run. We're going to also first before we do that, we need to actually call this method. So where do we call the player attack? Well, we are going to call it from the buttons. So we'll turn on the battle scene and we'll go into the scenes. And we need to select one of these. I'm going to select the attack bottom. So the attack button, if I scroll down, if I add a condition at the battle manager, go to the battle manager. What can we do in here? We need the player attack for some reason. I don't have the player attack. Is it a public key? Is public battle manager. Manager. So as you can see, for some reason, we cannot find the player attack. And why is that? Well, because if we look in here, we can see that it takes in two arguments. That is a big no-no. We cannot have two arguments. So what we'll do is we're going to add a parenthesis in here. We'll comment this out. And then we are going to create an integer in here. And it's going to be the selected enemy target. So we're going to copy this, paste it in here, and we'll just select the target that is 0. We'll save that. And now we should be able to see it in here. So when we hit the function battle manager, and there we go, player attack that takes in a string. And why is that? Well, because you cannot call a method in here that takes in two arguments. We will find a solution for this later on. Don't worry about it. This is just for testing purposes. So what's the attack? It's the slash. We will copy that battle manager, I mean attack button. And the attack button usually does the slash will save that. Excellent. So now it's time to run our game. So we're going to run or we need to turn off the battle scene of battle scene around the game had the BP. So now we can attack, we can choose to attack. So there we go. We attacked ourselves, which is not good. So you can see that all three of us at least we know that we can attack. So if we attack, let's say hit attack, Draco attacks the skeleton. The player attacks the skeleton. Also. Correct. Now we need to fix what we've done incorrectly in the dealing damage to character o k. So the thing that I did not take into consideration is that the enemies list starts off on the third because why we have the skeleton, whatever you call it the dark one. And Jimi solo, the enemies began on the third and the fourth integer. So on the, can choose either in here three or four. Let's choose 3. We save that. Now we attack the proper enemy. And I did not take that into consideration. So now when we attack, the one of our players should have the particle system on him and this made should have the slash effect on him. There we go. There we go. There we go. And you can see that we are being attacked and determines, if you've noticed are being updated on their own. So I hope you enjoy it. Don't worry, everything will be automated in the next couple of videos. When I see you, then.
107. Choosing Targets: Welcome back my fellow game developers to a brand new video where I forget to do a lot of things. But eventually we got it done. So when we run our game, we had DBT. We choose to attack. Who do we want to attack them to attack a warlord? Or do you want to attack them age, vote on it right now because we're attacking the warlord than we are attacking the major, then we are attacking the major again, but then the major axis. So let's not waste any more time and let's get started with choosing our targets. Okay, So obviously we don't want to have to choose a enemy from the code. That's complete nonsense. What we want to do is to have a way to choose a target from our UI. So let's do that. We'll turn on the battle scene. We'll go to the menu. We are going to duplicate this menu. We're going to call this the enemy targets and enemy targets. And we are going to, I think keep it in here. That's no problem because when we choose to either attack magic item or run, when we open up the enemy target, it should cover the attack anti magic, we shouldn't be able to then to anything else. So in here, the enemy target, we are going to go ahead and let's see. I'm going to choose these three buttons. I'm going to delete them. And I'm going to remove the, sorry, the slash attack and here, and this will change from the attack button to a, let's say enemy button. And the text in here is going to change to, let's say Target. And we'll make it so that it fits so auto size and increase the maximum. Maybe. I don't know. So we want it to be big enough. There we go. We'll set it just below it. But so there we go. So it's the target one. There we go at auto sizes and I'm going to make it a bit smaller on the edges. Okay, there we go. And correct. Now we're going to duplicate it. So we'll duplicate it once, twice, three times, and we only have a maximum of four enemies. So we're going to keep it as that. Now the next thing that we're going to do is create a script for the battle target buttons. So we're going to go and to our scripts into the battles. Going to make this a bit bigger right-click create a C sharp script that's going to be called the battle. Battle. Target. Buttons hit Enter. Wait for this to compile. And I'm going to attach it to every single one of these buttons. So I'm going to choose all of them. I'm going to add a component. I'm going to choose the battle target buttons. And we're going to open up the script. There we go. So now it's time to add a couple of variables. So now we want first of all, a movie name, so it's public, String, move name, and you'll see why we need a movie name in here. It shouldn't be even public, but we'll keep it as public so we know what's going on. Then we'll create a public and it's going to be the active battle target. Target. And finally, we are going to create a public tax mesh Pro. And it's going to be the Where is it? A text Mesh probe, the target name. We'll save that. Now it start, we are going to assign all of these and we can do this, or we'll simply assign this stack smash bro. So we're going to go and say that target name is equal to get component and children text Mesh pro going. And there we go. So it returns a text much pro and Stalin GST pro GUI GUI. So now this is working. Next thing we're going to do is we'll create a method in here for pressing. So what happens when we press the button? It's going to be a public. Void press. And what we do in here is we simply call the battle manager and get the instance. And we attack was the player, so battle manager, dot instance, dot player attack. And what do we send in here? We send in the movie name and we also send in the active battle target. So now we can go into the battle manager. We can remove the comments in here and we can stop this now this will stop the bottom from working, but no worries, we'll deal with that in just a bit. So in here we sent in the active battle target. We save that. And next thing we need to do is we need to actually get control of this target menu, or that's this enemy targets panel. Let's call it the enemy targets panel. And we turn it off and on based on when we press either the attack or the magic buttons. So let's do that. We're going back to our script, going back to our battle manager, will keep this as a common, as a reminder that we change something in here. Let me close down the damage. Dealer goes down the enemy. And in here, That's just created under the enemy attack or whatever you want. We're going to create a public void, open target menu. And it's going to take in the string move name. And this is what's going to be attached to the attack button. So in here we are going to simply get a reference to the target panel. So we're going to create a serialized field. It's going to be of type game object. And it's going to be the target for the enemy target panel. And we are going to set that panel to true. So in here, enemy target panel, reactive, true. Okay, great. Now the next step, 0, and let's set the reference in here. So the battle manager, the target menu, the target enemy, whatever the enemy target panel. Now we set it to true when we want to attack. Now the next obvious step is to change the names in here to the names of the enemy. And that's going to be part of your challenge. So your challenge is to load the enemy into a list, integer list. So create a list of type int for the enemies. Loop through all the act of characters. If the character is not a player, add them to the list and print out the length of the list at the end just to make sure that we cut them all. So pause the video right now and go create the enemy. And let's come back. So when we open up the panel, we are going to go ahead and get a list of ints. We'll call it the enemies. And we are going to create, make sure that it's a new list of ints. And what are we doing in here? Well, obviously we are looping through. And R equals 0 I less than the act of characters dot length, dot count, because it's a list I plus, plus. And in here, if the active characters on the eye position as a player. So that's why I said that if it's not a player, and then we are going to access the enemies list and we're going to add that in there. And finally, when we finish looping through, we are going go to debug log and we'll get the enemies.com. Save that back in Unity. We are going to turn where as the enemy targets. For now, let's just keep all the buttons. Later on, we'll turn them off and turned on only the buttons that we need. Let me just keep two of them. Because we know that we have two players, two enemies, and we need to turn off. The entire panel will go into the menu. The attack button we are going to, you can see right here that it's missing because we changed it. So from we're going to go to the battle manager and we're going to open target menu with a string which is going to be the slash. We're going to save that. We're going to turn off the battle scene, run the game, hit the B key attack. So now we have target one, target one. It hasn't changed unfortunately, but we can see that we have two enemies right here. So let's continue on. What should we be doing next? Well, obviously we need to be changing the names on the target buttons. So we're going to add a comment in here, common this out. And 4 and I equals 0. So you can see how useful loops are. I think we've created like 20 groups so far. So the target buttons, battled target buttons, we need to create that reference. So in here we're going to create a serialized field of type. Target buttons, battle target buttons. There we go. It's going to be an array, and it's going to be called the target buttons. We will scroll down again. We are going to loop through the target buttons dot length, and add i at each turn. And then if the enemies dot count is greater than i. So just like we did up here somewhere, Where is it? Where did we make sure that we had? In the update player stats? We made sure that the number of active characters is greater than the count. So we make sure of this in here. Also. The target buttons, position I got game object. That's sad, active, true. And we don't want to instantiate it. It's a bit hard and we already know that we have a maximum of five, so no worries about that. We can turn them on and off. The target button. At position i dot move. Name is equal to the movie's name that we've determined in here. And here that we pass on using the open target. Then we have the target button. We need to set the active battle target. So the active, active battle target is equal to the enemies at position I. And finally, we need the target buttons. I dot name, dot text is equal to the active characters. And what should we be accessing in here? It's the enemies at position i. That's because it's an integer dot character name. Oh, excuse me. The point should be outside character name. So what are we doing in here and what did we do wrong? Okay, So what are we doing in here? First of all, we are looping through the target buttons. We are making sure that we have the enemies, for that. We are setting it to true and the target button to true. We are setting the mood name. Why are we doing this? Because we are sending that movie name and the player at that. Then we are setting the target, which is the enemy at position I. And finally, we are getting it the name of the active character on the enemies at position I. Okay, so because we are getting the enemies, it's an int list. And then we get the position of the enemy inside of that IntList. And then we're using all of that to put it inside of the act of character and getting his or her name. Let's save that. And the last thing that we need to do is after the player finishes attacking, we want to get the target menu. Whereas the target menu, what did we call it? So our enemy target panel and then me, target panel dots directive false. So after we finish attacking, we want to close down the panel. We are going to go into Unity. What should we be setting in here? I forgot. So let's save that. Let's go into the enemy target buttons and we're going to turn all of them off. We save that. We run the game. We open up the battle, we do an attack. We don't have any names. Why is that? Because we haven't set the buttons and here, the target buttons. I knew there was something that we forgot to do. Save that wrong again, now everything should be in theory working very smoothly. So attack, we have a problem again. Let's double-click open up. What's the problem here? Okay, so if we click on one of those, we can see that we haven't given the target for it. Oh, okay. Okay. Okay. So we click on this button, we drag in the text, we click on this button, we drag in the text, we click on this button, we drag in the text, we click on this button, we drag in the text, we save all of that. We run the game. And now hopefully when we tried to attack, we have the magic major master and the war log n. Very small. Let's try to maximize the size. We start the battle, we attack the major or the war-like. Let's try attacking the war Locke. Obviously nothing happens because again, I forgot to set the onclick on all of these. Losing the battle manager, battle manager or not the battle manager, I mean, the, the actual enemy target. So we're going to, on each of those. There we go, the buttons, select all of them. Battled, target, the press, save that, run the game. So this is the third time we try to run our game when we attack, which shows the war lock that struggles on the major master Warlocks, okay, So we are attacking the same enemy. We need to fix that also 0. So I figured out the problem. If we run our game, we start the battle, we hit attack. We can see that the first one represents the button. It has a slash and the active battle target is three, the second one is four. And I was so baffled what is going on? Why is it not working? Every time we want to hit the Borlaug, we still hit the major in here. So the problem was, is that I made a very, that's called stupid move. When we choose a button, I've chosen all of them and I've set them one single target. We should choose each button, drag the script on it, drag the script on it. Drag the script on it, and drag the script on it. So now we choose the press for each of the buttons. There we go. So now we should. Finally. Yep, there we go. So as you can see, now when we attack the main page, we attack the war log. And there we go. So now we can actually choose which enemy we want to attack. How cool is that? In the next video, we'll see how we can use magic. So I'll see you then. Don't forget to commit your changes every single time we do something amazing.
108. Setting Up Magic UI: Welcome back, my fellow game developers. We didn't do too much on the front end of our game, but on the backend, we've created a lot of code with a lot of buttons and a lot of intricate and detailed functionalities. So let's not waste any more time, and let's get started. Oh, good time to use some magic with our players. Now, how are we going to do this? We don't want to have random magic happening and choosing for us that's good with the enemies, not so good when it comes to the player because we want to choose which spelled MY want to use. So let's go ahead and do that. First of all, we're going to turn off the battle scene. Where are going to go to the Canvas? We are going to choose the menu or the enemy targets, doesn't matter. We'll duplicate it. We're going to make it a bit bigger because we may add a lot more spouse in here. We are going to use the grid to move it from the top just a little bit and from the left just a little bit. This is going to be the, what should we call it, the spell choice panel, I guess spout choice panel. Call it something smarter if you want. And now let's make it a smaller, Let's make it this way. So two rows, two rows. Let's duplicate the EBIT, the Run button. So depends on how many spells you have currently. We don't have that many spouse. But as you go through your journey and RPG games, you know that you can collect spouse, learn new ones, increase your character stats. So I think having, let's say for eight spells, yeah, It's balls, I think is enough. And will make the box yay big. We are going to move using the grid debit, so move them up or the middle, or maybe add spacing. Know, this is perfect for now, we're going to delete all of these buttons, will only be needing one of them, which is the attack button. And we're going to change it to some kind of spell button. There we go. Going to remove the slash attack from here. And what are we going to do? Well, when we hit the magic button, it's similar to the way we use the attack button. We hit the magic button. We have options to choose one of the spouse that we have on the player. When we choose one of those spells, then we get the option to choose which enemy we want to use them on. So we are going to create this structure throughout our spout choosing panel. Let's get started. First of all, let's go into our battle manager. And two, where is it the battle manager? And in here we need a small reference. Let's close this down. A small reference to the spell menu. So serialized field, game object, the magic menu or magic choice panel. I'm going to keep calling get menu because I keep forgetting. And we need a method in here, which is the public void, open the menu. So public open, magic panel or magic choice panel. And we're simply going to get the magic choice panel that selective, true. Save that. Now let's go into the battle characters and give each their own moves to attack. So where are the battle characters? In unity? We go to the Prefabs, battle characters players. So Draco in here has the attacks available. We can add how many attacks he has, the gram and Jimmy. So let's see, Draco, what does he get? We are going to lock this down. We're going to go to the attacks. And here we can see all the attacks available. And let's make this a bit bigger. So what can Draco do? Well, I think as he's a bit dark, he can use the tentacles, both of them. And maybe not the purple ones. Not the purple ones, just the tentacles. Maybe he can use lightening. Sure. Why not? The lightning and the blue fire. I think those are good for Draco to use. We'll save that will unlock it, will go and choose a nother Butler. So the gram, what can the grim do? So Let's see. He can have laser. And lightening. So I think that's enough for the Gram. He is not a very overpowered character, is kind of a week. And then we have Jimmy. So Jimmy, what can Jimmy do? Jimmy can do everything so he can use okay, so we need to lock down Jimmy. Jimmy the demon, so he can use the blue fire, the laser, the purple tentacles, the black tentacles, and the lightening. There you go, Jamie, I don't think you'll have enough panel for all of those, which is going to be part of your challenge, not right now. Don't worry about that. Battle manager. We need to set the magic choice panel. So spell choice, magic choice, spell choice. I don't know. Back in here, we need two orbits, sorry. We need to stay in here and we need to create a battle magic button script. Each button in here that we're going to create in just a bit will have its own script on it. And we're going to do stuff similar to the way we handled the enemy targets. So in scripts in battle were right-click, create a C sharp script which is going to be the battle magic buttons. And we're going to add it to this file button. And we're going to open it up in Visual Studio. And in here we need a couple of variables. So first of all, a public String, spell name, then a public, and spell cost. Then we need two more variables for the texts. So public text Mesh probe. And there is one thing that I forgot to do, and that is the cost of this PAL. We need to make sure that the player that is using our spell knows how much this will cost. So I'm here going to name this the spell name and make it oversized. And maybe set a couple of things. Make it a bigger. There we go. And I'm going to add a text much pro in here. And where are we? Text Mesh Pro. This will be the spell cost. This is the spell name. And disposal costs to be set down here on the bottom. It's going to be the form that we are used to. We're going to auto size it. We're going to make it bold and we're going to set it to three nines. I hope that looks good enough from behind. So hopefully this will not look very bad. There we go. We'll set it right there. This is the proper size for it. We don't want it to cover the V spell name too much. Yep, there we go, we save that. Let's go to this button. And now we'll get a reference to it also in here. So the spell name text and the spell cost text. And then we're going to create the precedent here. So let's remove the start and update. We might need them later on. So public, void, press. And the battle manager dot instance, dot open target menu. And what does it require in here? It requires the movie name, so it's going to be the spell name. Save that. But we can't just do this. We need to make sure that the player has enough mana in order to use this spell. So I'm going to issue you a challenge. And your challenge is to make sure that the player has enough mana. So how do we know the player has enough mana will need to access the active character on the spell button. So the first thing that you need to do is to access the variable of the current mana on the battle character. So you'll need a method that returns the character from the battle manager. Then when you press the button, create an if condition that calls that method and checks if it's enough for the spot. So pause the video right now and go do the challenge. Okay, welcome back. So in the battle manager, we are going to return the currently active character, so public battle character. And in here we're going to get current active character. I wanted to call him butler or character, and will simply return the active character on the current term. And that's all that we need to do. We'll save that. We'll go back into the magic button. And in here before we cast a spell, will create a condition. We'll go to the battle manager, dot instance dot get active character. And we are going to access the current mana on him. And we're going to check if he has more than the spell cost. And then we'll move the battle instance in here. And what else should we do after we press that button? Well, we want to first of all close down the menu. So battle manager, the magic menu option or spell choice panels, something like that. We'll see. So battle manager dot instance, dot magic. Nope, Let's go into the battle manager. We need to make sure that it's the magic choice panel. We can create a method to alternate or we can just make it public for now. Just to make things a bit easier, we save that. So instance magic, choice panel that set active to false. And then we also need to remove the mana from the character. So battle manager dot instance, dot, get active character, dot current mono is less than or equal than the spout cost o k. Great, so now we save that, we go back into our game. We are going to save all of that. And in the next video, we are actually going to be assigning the scripts to our button and changing them around. I need to cut the video right now it's already too big and there are a lot more steps to do. So. I'll see you in the next one.
109. Using Magic: Welcome back, My favorite game developers. In this video, as you can see, I've won a battle. I'm so proud of myself. When we run our game, we hit the B key. We use magic. As you can see, we have lasers was lightening which require 120, the lightning. So we're attacking with the Gram when we had the warlord, you can see that we lose a bit of Mona. And we can do the same when it comes to Draco, lightning master, we can choose which enemy we want to attack. We can choose with which spelled we want to attack. We can choose whether we want to use magic or simply attack them. And all of that will be possible in this video, of course, we need a bit of tweaking. You'll notice at the end, there are still a lot of things that we need to do as we play through the battle and check out some of the inconvenience that we have there, some bugs and so on. So until then, let's not waste any more time. Let's get started and make sure to always commit the changes that we make in this video. Oh, okay, so no need to explain anything. We'll just continue on with our magic using powers. So let's open up the battle manager. Let's scroll up and let's get a reference to all the magic buttons. So a serialized field with the battle magic buttons to recreate that. We did. And the magic buttons. There we go. Now, let's go and get a reference to them. So or disposal costs. I'm not sure I spell magic buttons, whatever you want to call them. Let's call them magic buttons. And we're going to add 1, 2, 3, 4, 5, 6, 7, 8 or enough. Let's go to the battle manager. Close that down. Select all of the magic buttons, add them in here, turn them all off. So we take over France with it. So like all of them and turn them all off. Great. Now let's go back into where we open our panel. So in here, we are going to look through all of them and turn them on and off and said their names. So four and r equals 0. I is less than the magic buttons. Dot length, dot length I plus, plus. We are going to check if the active characters of the current turn. Dot attack moves available. Dot length is greater than i. So this is similar to what we're doing. Every time we have buttons, we need to make sure that we have more attack moves available. We're going to check for the magic buttons at position i, dot gameObject, dot set active, true. Then the magic buttons at position I thought spell my name is equal to get active character. So now we have the get current active character. How cool is that? So we can use him in here because it returns the current. We could have also used him in here, but we're just getting used to it. So dot-dot attack moves available at position I. We save that. And finally the magic buttons at position i, dots bell, name, text. There we go. The text is equal to the magic buttons at position I spell name. So because each battle magic button has a special name, then we are going to access the spout cost, spell name text on it and set this band name. We could have also made it in here on the start. Maybe just maybe this would have been better, but because we're setting everything in here and here in the bathroom manager, let's just keep it in here so we know. Okay. So we open the panel, we set everything for the bottom not we set half of the things in here than half of the things in here. So back in the battle manager. Finally, what we need to do is we need to check or fill, actually dispel cost. And that's going to be your challenge. Your challenge is to get this podcast and apply it. So looped through the battle moves, use j instead of I because we are already using the I. Check if the names match up with the name of the spell on the button. Set the spout cost on the button, and set it on the text also. So pause the video right now and go do the challenge. Welcome back. So it was a bit of a hard challenge, I think. So we're going to create a for loop, and the for loop shouldn't be in here. It should be in here. So four. And we're going to go ahead and create an int j equals 0, while j is less than the battle moves list dot length j plus plus. So we are going over all the battle moves. If the battle moves less, position, j dot name is equal to the magic buttons. Position, GA, position, I mean dot, spell name. Was I writing this whole time outside the brackets. Okay. So we make sure that we have it available than the magic button. At position i, dot spell cost, spell costs. Normal cost for now is going to be set. We need to remove it from the player. And let's duplicate this line. Spell costs, text, battle move. Or we can immediately use this one in here. Copy that, paste it in here, spell cost dot ToString. There we go. So now, let's save that. Let's go into our Unity. I'm pretty sure we forgot a lot of things. The problem in here, What's the problem? Strings to text Mesh. Oh, okay, Okay. Text. Save that. Now we shouldn't have any errors. Okay, great. So now we are going to get this. We're going to see it required. They all require a bit of work. So I think we can leave those and go ahead and check for the spell name text, the spell costs text. And we are going to add in here the press. Save that. Let's duplicate it. How many did we have? Let's turn it on. See how many there were. Save that. So you can see right now this is how we handle it. So each the magic script of the button in here is used on this one. So before you duplicate the buttons, make sure that you create the first one precisely and correctly and then duplicate them. So for example, let's choose the button in here. If we chose the script, the script on the magic button that we're using. If we choose dispel name as dispel name of the button that we're choosing. So hope that's understandable. We are going to turn all of them off. We're going to save, we're going to close down the choice panel, run the game. Hit the B key, shoes, magic. Why isn't it working? Battle manager, spelled tours panel. Okay, on the menu, The magic. We forgot to do the most important thing which is opened the magic panel. Open magic panels, save that. No, no, no, Don't run the game. We need to turn off the battle scene, run the game. Let's go to the magic. And there is a problem. The problem is in here and that the magic button isn't referenced correctly because because y is not referenced correctly, but you can see that we have the laser. We can choose the war Locke, and we've applied the laser. So lightening. Okay, So there is definitely something wrong. That's because if you go to the button manager, what's the problem? Oh, okay. So he we deleted everything. And then we didn't make sure that to add them again. Okay, there we go. It's so nice that we can actually double-click on the air and go immediately to the wrong line so we can start diagnosing. Again. Let's run, Let's test this out. Hopefully, this should work when we had the magic, we have laser enlightening because we're working on Draco, I believe at first. So if we unclick this, let's go to Draco, Draco, Draco, draco. Prefabs players. Draco has lightning tentacles. No, I think it's the Grim. So. Lightning war Locke. Yep, there we go. We applied the lightning on the war luck and we've lost all of our mana. So now we are using Draco. You can see that we have the spouse that we can use. So we're going to use the tentacles. We can't use them because I don't think we have enough mana. So for example, the lightening needs 120 mono while Jacob, I mean Draco has, let's see. Draco has mana, 10. Okay, Very nice. So what's the problem? I think we did something wrong with our code because current mana was lost and I don't think so. All we have to little Mano. So the current mano stand and the maximum is tan. Of course we cannot use those. Of course, of course we cannot use those. So we'll need to go to Draco. Let's add a bit of mana to him. Seriously, let's add a 1000 thousand and the grim, a thousand with a thousandth. And the player. Let's apply the light to Draco, applied to the grim. Save that we'll run the game again. We'll start the battle. And yes, this is game development. You always do something. All of these need testing, so lightening, lightening on the main master. There we go. If we collect on the Grim, we can see that he has lost current Mano 120. He lost some mana. Draco has the amount of mana. Again, we use magic. Let's see. We want to use the blue tentacles or something. We are going to use them on the warlike. They cost 200. So when we had the war Locke, we should see that. Oh, so we've already lost. There we go. When we hit, we use the again magic and let's use the purple tentacles on the Warlocks. Did you just see that? Because we hit, I think a critical there we go. Jimmy dealt 2772. Whoa, Jimmy, that's some number. That's a lot of damage. So now again, we start. But as you can see, we still have a small problem and here, it's not updating. We have all these files available to us from every single character, again, magic. So you can see that there is a small problem in here. And the last step that we forgot to do was to create an else statement in here and said the magic buttons at position, I thought game object set active to false. So now we shouldn't see spells that should not be there. We run our game. We had the magic use lightning, magic use on the Warlocks, magic, lightning. So magic, as you can see, because we are on Draco, we don't see any other attacks. Magic, and you can see that we've killed the world walk. But we haven't removed him from. And because Draco's that we can only attack. So you'll see that there is only one term for the enemies and one term for us. That's because the war-like has died, but we can still attack him and we are still attacking with Draco 0 because he hasn't died yet. So we use lightening on the wall. Luck can see he does not attack anymore at all, but we can still attack him, which is not good, not enough magic. Hey, we want. So I hope you enjoyed this video. We can finally when a game, and I'll see you in the next.
110. Showing Not Enough Magic: Welcome back, My favorite game developers. In this video, we have a notification panel that tells us various things. And one of the most important ones is that if we try, if we have 0 mono or not enough mono for a certain spout, which is the lightening. Let's say we try to hit the lightning, but we don't have enough manner, so we need to do something different. Anyways, let's not waste any more time and let's start adding notifications to our battles. Oh, okay, so currently when we don't have enough mana, we cannot do any magic, but that's not enough because we cannot see, or we cannot know that we don't have enough mana to do it. So what we'll do, we'll take this opportunity to create a notification bound. So how are we going to do this? I'm going to open up the canvas. I'm going to go into the menu. I'm going to find the attack button. And before I continue, I need to turn off the battle scene. I'm going to use the attack button. I'll duplicate it. And I'll uncheck that from the battle Canvas or you know what? Let's keep it in the battle Canvas. We'll just put it over the menu. And this will be the battle notification. So, but no TV cation panel, you can call it if you want. We're going to remove the button component because we won't be pushing it. And I'm going to set it in here. I'm going to make it a little bit bigger. Settled right here. So this will be used for general purposes. So I'm going to open up the text and I'm going to change the size of that text to be around yay big. There we go. I'm going to set it in the middle and I'm going to make sure that it's ostracized and increase the maximum as much as I can. And the minimum as small as I think I can. And this is going to be the battle notifications and make sure to auto sizes because you never know what kind of notification you want to put it in here. So because it's a general purpose and notification panel, we are going to use a script in order to manipulate it. So let's right-click in here, go to create C-sharp script, and we're going to call this the battle notifications. Enter. Wait for that to compile. We're going to add it to the baton certification. And we're going to open up the script. Oh, great. So what are we going to do in here? First of all, we'll need a reference to a couple of things. The first thing will be, how much time will this stay on screen? So it's going to be a float, time alive. And then the second reference will be obviously to the text or the text Mesh Pro. So we'll need to use the AMP. And this will be of type. Thanks, mesh pero Gui. The text notice, which is text notifications, will remove the start and update because we don't need them for now. And I'm going to create two methods in here. The first one will be a public void set text. We're just going to take in a string of text. I mean, I mean a tax of type string. And then what we'll do is we'll set the text. Notice that's to be equal to the text that has been sent. Then we'll create another method to activate this game object of battle notification. So it's a public void activate. And in here we are going to simply get the game object and set the active to true. Okay, Now the next thing that we want to do is we want to turn off this notification or set it to set the active to false after a certain amount of time. How do you do this? I can hear you almost it's using coroutines, okay, so we will use Coubertin's. But you are going to use coroutines because you are going to make the notification disappear by creating a co-routine that will make the notification disappear after the time to be alive ends. So pause the video right now and go create this easy covertly. Hey, welcome back. So this wasn't a too hard of a challenge, I believe, because you are already familiar with coroutines. We've made a ton of those. So this will be the Eigen numerator that make, nope, this, this beer. Is that how you write disappear and then we are going to yield return. That's not how you write return new. And we'll wait four seconds until the time to be alive. As over. Save that. And finally, after we've waited for that time, are going to access the game object. Dot set active. To false. We'll save that. And after we've activated, we are going to start the co-routine, which will make the notice. Ok, cannot rename this element. Maybe we should add brackets. And this should be with an IEP Enter. And I'm not sure if you know how I'm doing this. I pretty sure that we covered this, you hold down Control or R and you can change every instance of this world. I hope I haven't been doing this without your knowledge. Anyways, let's continue one, where are we going to be calling this? Well, obviously in the battle magic buttons, after we push this button and we find out that we don't have enough money to use this spell. Else, we are going to use the bathroom to vacation, but there is a slight problem in here. And that is not problem actually a, a code hierarchy or cold implementation way of thinking because we are going to be using this battle notification in many instances in our battles, because it's not just for the 0, we don't have enough money. Or maybe all we've ran away or you can't run away or you've done a critical damage hit or anything. So because we are going to be using it throughout our battle, It's better to get a reference to it in the battle manager. So I'm going to close all of these. And in the battle manager, I'm going to get a reference to the battle notifications and the battle notice. And we are going to access the battle notice on the battle manager and then use the methods on it. So the battle manager, dot instance, dot battle, notice this should be public. Obviously. Should have noticed that forehand, no worries, say public variable. So the battle notice dot setText. And this tax is going to be, we don't have or something like that. And then what we'll do is we're going to activate it. So battle manager dot instance. We should have created a single variable for these three words. No worries. And in here also, that would have been a lot better. And finally, what do we do in here? We turn out the magic menu. So battle manager, that instance, the menu magic, magic menu, magic choice panel that set active to false. That's it. And some of you might be wondering, why are we using one method to set the text, one method to activate it. Why not just set the text and activated while? Because maybe along the way, you'll need for some reason to set the text separately and then activated separately. You can set them on the same method. It's okay, No worries about that. But I think it's better, cleaner and maybe will be used later on to just set the text or just to activate for some reasons. Not worry about that. Let's save that. Go back to our game in here. Will need to go to the bathroom manager and give him the battle notification. Or before we do that, we need to set the text notice. And let's put a two seconds. Then we'll go to the battle manager and give him the Battle of nodes. We're going to save all of that. We are going to go ahead and turn off the battle scene. We'll run our game, will start the battle. And for obviously we should turn off the battle notification will run again. We'll start a battle. We are going to go to the Layers position, position one, the gram, the current Mano will be set to 0. We'll save that. We can save during game mode, so we access the magic. Let's try the laser. We don't have enough manner and it turns off so great, this seems to be working. I hope you enjoyed this video. I hope you're having fun. In the next video, we will see how we are going to kill our enemies because currently they are sort of invisible. So I'll see you in the next video.
111. Running Away: Welcome back, My favorite game developers in this video, when we run our game, when we hit the B key, we had the Run button, but we've never used it. So now when we hit the Run button, as you can see, we can run away. But sometimes when we hit the Run button, we can see that there is no escape, so we can not run away from our problems. We always, or sometimes, or most of the times have to face them. So let's not waste any more time. Let's go face our problems and let's get started. Okay, so now we want to give a chance for our players to runaway because we are facing overpowered enemies or enemies that are way above our fighting level. So let's go ahead and create a method for that. We're going to go to the battle manager. And whereas the battle Manager, button manager, I'm going to put it in here. And we're going to create a variable in here, a serialized field, which is going to be the chance to run away. So this is how much chance Do we have the chance to run away? And we're going to set it to 0.5. So this should depend on each bath. And then we are going to scroll down to the end. And in here we are going to create a public void, run away. And what are we going to do in here? Well, I'm going to issue you a challenging because can we even escape? This is the question that you need to answer. Create a method runaway, which I already did for you. In it, you'll need to check for a random value. And if it's greater than a certain threshold, we let the players escape. If not, show a notice that there is no escape. So just like we did when we were implementing the critical hit, you'll need to go ahead and implement this in our running away method. So pause the video right now and go do the challenge. Okay, welcome back. So the first thing that we're going to do is get a random dot value. And this will give us a value between 01 and if that value is greater than the chance to run away because the chance to runway is 0.5, if I remember correctly, yes. So if it's greater, that means we have a 5050 chance of running away, then we're going to set the is battle active to false. And the battle scene will also be turned off. In the battle symbol set active will be turned off. And else. If we can't run away, then the next term will be done. The battle notice dot setText will be there is no escape with an exclamation mark. And finally the battle notice will activate. We'll save that. We'll go back into our game. We're going to go to the button in here that allows us to run away. So the menu, the Run button, we'll add an on-click method in here. So there we go. We'll drag in the battle managers. The gameObject will access the battle manager and we are going to run away. So we'll save that. We'll run our game. Hit the B key, will try to run. There is no escape. Let's try it again. There we go. So we were able to escape the second time. If we try the battle again, you'll notice that we have a slight problem in here that the grim Draco and Jimmy are created again. The first ones are and being destroyed. So this is a big no-no. We don't want this to happen. We'll be fixing that later on in our videos. But for now, as you can see, we have the ability to runaway from battle, which is a bit cowardly, but we are able to do that. It's an option. Anyways, I'll see you in the next video.
112. Using Items During Battle: Welcome back, My favorite game developers and this video, when we run the game, when we pick up a couple of items, when we start a battle, if we want to use some items, there we go, we can see that the items that we've picked up our right here in our inventory, ready for us to use. If we click, we can see that this is a silver armor. This is a nice ocean. This is a golden axe we cannot use, we cannot close, but they're there for us to use. So let's not waste any more time and let's get started. Oh, okay, so the last button that we want to use is the use Items button. So let's go ahead and implement this in our code. We are going to, first of all, excuse me, before we implement this in our code, we are going to create the menu for it. So what we'll do is we'll go into the canvas and to the items Menu and to resist where visit the items panel. And we are simply going to duplicate this panel. We're going to drag it all the way into the battle Canvas in here. Okay, so we're going to turn this on and then we are going to do a couple of changes in here. So the first thing is we won't have that big because I feel as if we're going to click on here. And we'll see, we'll call this the use items panel. And we are going to change a couple of things in here. We're going to move this up. And some of the items in here needs to be fixed. So I'm going to do this one by one and maybe I'll see you after I finish reorganizing everything. Ow, kay, welcome back. So what have I done here? First of all, I've changed the layout of the items of it. I changed the item in here, the item button. So I'm going to delete all of these is we're just so I can lay out the grid correctly. I've made this item 0.7 on the scale right here on the Rect Transform. And I'm going to prefab this. So I'm going to go into the Prefabs. And where should we be saving this? Where did we save the previous one? Let's just save it inside of the battle. Maybe. Let's change this from battle characters two, or let's save it and items maybe. I don't know. Inside of the battle characters, I'm going to rename this to the battle prefabs. Battle prefabs. And I'm just going to use this item in here. I'm going to create an original prefab. And it's going to be called the battle Items button because we are going to be instantiating every time. And this is going to be the but Items. Button. Hit, Enter. There we go. We save that. What else did I do? I changed the character choice panel a bit, so I made sure that everything aligns in this smaller menu. I'm going to turn this off. We keep everything the same. But maybe later on we should remove the onclick. And here, you know what, let's just remove them for now. Unique values, different objects, lost. No worries about that. Let's just remove this on click because these are going to use different methods, I'm sure. And what else did we do? Let me turn this off. At the items display panel, I made a bit smaller just so it can fit inside of this place or the place that it has. The US button. I also removed the onclick. It's still the same. I just changed the size of it. I changed the discard button into the close button, because now we're going to use this to close the menu. If we don't want to use the items anymore, we could have just used the items in here, but no worries about that. The items name and value and the description, all of them are set to be 0.8 on the scale and just positioned differently. And I think that's all I did think so. So there we go. I think that's everything that I changed. And this use items panel for the battles. Now, let's go back and let's start coding. So the first thing we're going to do is in the battle manager, we are going to go up and we are going to get a reference to all of the new things that we've created. First of all, we're going to create a public game object, which is going to be the items to use menu, I guess we can call it or panel, call it whatever you want. Then we are going to create a serialized field, which is going to be of type items manager. And it's going to be the selected item. So it's almost the same as when we created the inventory and the items on the normal Canvas. You'll see that we even use the same method. So the second or third reference is the item slot container. And this is where we will set all the items. We will put all the items. I mean, this is the Items button that we are going to be instantiating. This one, which is going to be a transform, is going to be the item slot container parent. And finally, we are going to get the items name and description. So the serialized field which is going to be taxed much pro and con to be the item, name, item, corruption. There we go. Next thing we need to do is we need to create an update items in inventory. So we're going to update items in inventory. I should have, first of all, make sure that let's say public void. And then we are simply going to go into our Canvas manager. What was the name? Look how many scripts we have. So I'm going to go into menu manager or is it, um, okay, so let's go to the script from our wait for this to combine canvas menu manager. Also it was called Menu Manager. So in here, somewhere we have the update items, so we're just going to copy this because I've copied it, will copy that with the name or going to copy. We're going to go into our battle manager and we'll paste it in here. So the item slot container. Copy. There we go. Save that because this is the exact same method what we're doing. We're destroying all the items previously held or appeared. Then we go through each one of them. We what do we do with instantiate? We set the image, we set the tax, the amount and the last one, which is the item on the bottom. Okay, great. Now the next thing we want to do is we want to use the item selected for that. We need to go ahead and issue you a challenge. So your challenge is to select the item you need. So you'll need to create a method called selected item to use with an argument or parameter of the item that we want to use. Then energy will need to set the selected item and print out the name and description. With that, pause the video right now and go do the challenge. Okay, welcome back. So in here we are going to go ahead and create a public void selected item to use. And it's going to take N and items manager item to use. And in here we are going to set the selected item as the item to use OKR. So for that because we've written items not item, then the item name is go dot txt is going to be equal to whatever the item to use or we can use the selected item. So the item to use dot item name, then the item description text would be equal to the item. To use that item description. There we go, save that. Now. We need to use the press method that we have on our buttons. So in here, let me show you. We can see that on the prefab that we've created, which is in the battle. In here you can see that we have the battle. So open up the script for the button. So in the bottom right here we have the Items button script and we're going to use this. So we're going to double-click on the Items button. And here if you remember, we have the press method, but now we are going to add another condition. So first, we use the two. If we have the menu active than if we have the shop menu active. Now if we have the bottom active, so we're going to check if on the battle manager dot instance, dot, items menu or the items to use menu, dot is active in the hierarchy. Then in here we're going to access the battle manager dot instance, dot selected item to use. And we're going to set it as the item on the button. Item on button, save that. There we go. And now to test this out, I'm going to go back into Unity. I'm going to exit the prefab or the item on the buttons should be set. And here, we've already created all of that. I'm going to go back. I'm going to go ahead and add a couple of items on the ground. I also wanted to do something in here. Oh, Turned of the what should we be turning off? The items panel? Yep. There we go. We need to make sure that this is off. And we need to set a couple of things in here. Yes, that's what we need to do. So we'll open up the US panel. So first of all, we need the items to use game object. There we go. The selected item which will be set on its own. This could have been private, but we use it in different places. So the item slot container, and this is going to be the prefabs on to click on here. Go to the Prefabs, go to sea battle. And this will be the item slot container. We will have the items display panel, which should be in here, the container parent. We have the item's name. So if we open up the item description, This probably should have a better name, the value. And the value. And I think that's it. We're going to save all of that. We are going to close down the battle scene. The battle scene. Save that. Open this up. And before we forget, we'll just zoom in on the player at a couple of items in here. So if we go to the Prefabs, the items, let's add the x, the portion, two portions, the armor and the silver. So we'll run our game. We are going to go ahead and pick up the items. There we go, we've picked up all the items. Now we are going to start the battle. We are going to open up the items Menu and it's not working. Why is that? Because obviously we didn't set the items button to do anything. So these are very crucial steps that I keep on forgetting. So in the US item, what do we do in here? We need to call a method in here, but that method, which is the update items, should also set the items menu to open. So we're going to type in here the items to use manual dot set, active to true. We'll save that. And we'll probably need to go back in here and change a couple of things. So for now let's just add the battle manager. The battle managers should update the items in inventory. We will save that. Now when we run the game, we're going to pick up these items, start the battle. And as you can see, because we were walking, we continue on. Anyways, we're going to hit the items and there we go. When we click on the Items, we can see the description and their name down below. Now we cannot close, we cannot use, we will do those all of those things later on as we go. If you want, you can go ahead and close this menu, but not only that in the next video, we are also going to be able to choose which player we want to use that item on. So I'll see you then.
113. Selecting Player To Use Item On: Welcome back, my fellow game developers. In this video, we actually know what on whom we are going to be using the item. So we pick up the items, we go into battle. And let's see, we choose the grim. We've already tried this on the gram for the HP that strike on the mono, so we'll put him to 20, 10, 0. We need to remove the current model, so we'll set it to 20. We're going to not save that. Go to the items selected monopole ocean, whom should we use it on? We'll use it on the gram. So keep an eye out for current mana and here and his player stats. So we use the gram. There we go. We increase demand by a little bit. But as you can see, every time we use an item, we update the player stats. So there you go. We've updated this and we can close down the menu and continue the battle. So let's not waste any more time. And let's get started. Okay, so now it's time to start choosing which player we want to use the items on. So the first thing is that we want to get a reference to the character choice panel or what did we call it in here? The battle manager but Canvas, character chores, panel, Yep, it is character choice panel. And then get a reference to the three names that we have in here and turn them on and off. So let's open up our scripts. And in here in the battle manager, I'm going to go up top. And I'm going to get a reference first of all, to the game object, which is that of the panel. So game object, the character choice panel. And then I'm going to get a reference to all the texts that there is. And now I'm going to go ahead and issue you a challenge, which is to create the open characters menu. So it's very similar to the one used in the menu manager. But instead of just looping through the player stats, we need to loop through the act of characters. And also we need to make sure that these active characters are the players, not the enemies. With that said, pause the video right now and go do the challenge. Okay, welcome back. So I am going to scroll all the way down and I'm going to create a method in here which is going to be the public void, open character menu or characters menu or whatever you want. And then we're going to check if we have a selected item. If we do, we are going to go ahead and first of all, check 40 character choice, panel, choice, panel dot set active to true. So now we can start choosing. Then we are going to loop through the V active characters dot count. And we're going to of course be adding just one. Then we are going to check if that is a player or not. So because we don't want to add anything to our enemies. So if the active characters at position I thought is a player, then in here we are going to go ahead and access the player stats were first create a method. So player stats, active player. And it's going to be equal to the game object or game manager. I mean dot instance, dot player stats. At the position I. Then we are going to access the player name. And the position I that we've referenced up there. The text is equal and that I make texts. It's text Mesh probe. So there you see, I've learned from my mistakes to only took me about three or four times the act of player dot player name. And then we are going to either turn it on and off. So we'll create a Boolean. So we'll call it the active player in hierarchy. And I wanted this to avoid having to type a long name. And apparently I typed in a long name again. So game object dot active and hierarchy. And in here we are going to access the players. Names at the position I dot transform, dot parent, game object dot set active. And it will be active based on if the active player and the hierarchy, we'll save that. And finally, if we don't have a selected item, we can send a notification. If you want. We can use the notification panel. But for now we'll just simply print no items for item selected. Save that. Next thing we need to do is we need to use this item. For that, we need be able to change characteristics in the player's character or anti battle character. So we're going to find the battle characters. We call them, but there we go, battle characters. And in here we are going to create a couple of methods other than the take damage. We're going to allow him or her or whoever it is to use the item in battle. And it's going to be a, It's going to use a parameter which is the item to use the items manager. Then we're going to check if the item to use dot is item. Or we can check if that's the case. If we go back to the items in here, in the items Manager, Items manager up here, we need to check for the 0, okay, so the item type. So we'll go back into our battle characters item to use dot item pipe is equal to the item manager dot item type dot item. There we go. So if that item as an item and if the item to use dot effect type is equal to the item manager. So this is a bit of a hassle, not the item dot effect type dot HB. Then we are going to add HP. Obviously we don't have the method to add each bead, but we'll create it down here. Then else, if we're going to just copy this line, long, long line dot effect model. We could have just used the else, but that's not get away of ourselves. So add mono, and we'll create this method in here. So let's go ahead and create both, both of these. And we could have just generated it. And what that means, send this to the item two U dot effect, amount of effect and item to use dot amount of fact. Let's go ahead and generate the mono first. And in here we are simply going to get the current Mano plus equals the amount of fact. And in here also we're going to right-click to Actions and refactoring generate method, the 0 current HB plus equals amount of effect. Save that. Now back in the battle manager, what should we do in here? The final thing is when we actually select a player. So what's going to be a public void? Use item button. So this is when we actually click on the player, or we could have called this the US character or choose the player. Let's just keep it at that. So ent selected player. And I don't think this is a good name. I'm not filling. My intuition tells me that this is not a good name. Anyways, the active character on the selected player dot use item n, battle for the selected item. There we go. And then we are going to go into the inventory dollar instance and we're going to remove that item, which is the selected item. We are going to update the player stats. Because obviously maybe we've added a bit of mana, let say. So we're going to update the player stats. Where is the update player stats? Update player stats. And then we are going to close the character menu. So let's create that method in here. So public void, I know these are a lot of methods that we've created, but they are very basic because we've already sort of done this previously in other places or when we wanted to choose an item or use an item during gameplay. So these are all very, very similar. That's why I'm not going too much into detail. I don't think there's too much to say we created to use item. It just checks if it's an item or not, and so on. So then in here we are going to access the character choice panel, dot set active. That's going to be false. And finally the items menu. Or maybe we shouldn't close the items used manner just for now, or we can close it. I think it's better if it closes. So the items to use manual that set active false. So in here we are going to close the character choice. And finally we are going to open up the menu again. So why are we doing this? I'll tell them just tape it open the where is it? Okay. So it's update items in inventory because this is what gives us the item, save that. So why are we doing this? We just want to make sure that we cannot use that item. Why are we closing it in here and then opening it up? Well, because we want to update it again. So we're going to save all of that. We are going to go back in Unity. There are a lot of things that we need to add in here. I hope you don't forget anything. Wait for this to compile. So battle managers scroll down the character choice panel. There we go, the player names. Going to logs down, choose the player choices, add them in here. We can't because it's a type of text Mesh pro. There we go. We've added that were saved that we need to click on the buttons in here. And each of those should have some kind of onClick entry and which one that is. So first of all, let's handle the US button and the close button. So what does the US button do? We'll add the battle manager in here, will search through the battle manager and will need to open the characters. So open character menu, the close button. If we drag down, we will close. Where is it? Closed, closed pools, closed character choice. I see something okay, open. So we'll close the character choice, which will close the character choice panel and the items. You could have avoided this record of change the name, but no worries about that. We're using it in two places for two different purposes, not going to harm anything. And finally, we need to, we've added the US button. We need to make sure that the player choice button do something. So in here we are going to add the battle manager. We're going to go to the battle manager and use the item button. So this is what I meant. Display player will be 0. These two also have the same battle manager. With the battle manager use button item and it will be the player one and player 2. We are going to save all of that. We are going to run our game and hopefully we haven't forgotten anything. So let's go pick up a couple of items and you know what, let me just add one more portion in here for the mono so we know it works. Prefabs. Where are the items? Let's add a portion in here. Let's see if that. Let's run the game. Let's go ahead and pick up the items. Had the beekeeper let's see, let's see if we can take down. Go to the gram That's remove able of the current HP and maybe set it to 50. There we go. Hit enter. Now if we go to the items, we go to use the HP portion, we had the US key. We can choose whether we want the grim Draco or Jimmy to have it. So we're going to give them to the gram. And there we go. We've added 50 HP. This will give you HP. There we go. We can see it in here and we can see it updated and the player stats. How cool is that? We haven't added the ability to use the armor, by the way, to add them to Drake or Jimmy during battle. I'm not sure how that is going to affect our gameplay. Or actually, I'm not sure if foo should be adding a during battle, but it's fairly easy. We can go ahead in the battle characters. In here, I'll give you this challenge outside the realm of our gameplay, you can add it in here. So if it's not a typical item that affects either HP or mono, you can check if it's an armor or if it's a sword, and then you can add it to the bachelors. And here, even though we changed the weapon power, you don't need to actually add the item to that character. Just change the weapons power and the weapons defense. But with that, I hope you enjoy it. I hope you solve the complexity of which we needed to use items on our characters. It was really fun. It was really complicated code, which is very nice. If you're not sure how all of that works, just follow the code, goes through the code again, once or twice, make sure that you understand how each one of those are being affected, how everything is changing, and I hope you enjoy it and I'll see you in the next one.
114. Section 17: Dealing With Dead Players: Welcome back, my fellow game developers. Finally, in this video, we get to kill our players. Yea. So now we start. Let's attack a bit. So let's wait for one of them to die. So Jacob dies. As you can see, we have particle effects and Draco coastal sleep, That's strategical, another one gram. So when the grim dies, he also gets this cool looking particle effect. Well, it's not that cold, but he also kneels and dies, and Jimmy also dies. But unfortunately, we won't be able to see him because, uh, because, well, he, he dies from the attack of one of the enemies and we stopped the battle. But as you saw, everything is working fine. So let's not waste any more time. And let's get started. Oh, so at the moment, our players don't die, but they no longer have any HP. They no longer have a turn, but they don't die. And we actually have a place to handle the players dying. In here It's when the active character has an HP that is equal to 0. So let's go ahead and implement that. How are we going to do this? Well, there are going to be two things that we need to do upon the death of one of our characters. One, we are going to have a particle appear, so some kind of smoke as being a blown up. And the second one is we are going to change this pride when that happens. So if we do have, or if your character does have one of these sprites where he is dead, like for example, the skeleton. And here if we open this up, we can see that maybe he does have one of the dead sprites, for example. Let's say we could pass this as a dead skeleton. But for Jimmy, There is no that sprite. Wherever we look, we are going to have to be a bit creative about that, and I'll show you how we'll do that. But first of all, let's go ahead and create a particle system. Now, I always encourage you to go and create your own. I already have one prepared that I'm going to use, which is the player's death affect this could have been named the characters that effect. It doesn't matter. You can name it whatever you want. We are going to use it on the characters also. So I'm going to change this to the character that affect that fact. And I'm going to drag this right here and the assets. And as I've said, and what should we do in here? I'm going to import this and we're going to have a different folder and the prefabs. So prefabs, so I'm going to set this in a different place. I think this is a good place to put it. So I'm going to drag the character effect. And to the player. What is this battle prefabs? I'm going to delete the folder facts. We don't need it. Okay, so now we have the effects. Next we need the sprites and how are we going to do the sprites for that we are going to use? And I'm going to do the same for the dark soldier. And the skeleton will already have his own that sprite, which will be one of those that we'll be using later on. But anyways, now you know how you can create that sprites even if you don't have that. Okay, So the next thing is we're going to get a reference to this. So I'm going to go into our battle character. So battle characters. And in here I'm going to make sure that it's public. And then we'll create a sprite renderer. Oops. A sprite renderer, because this will be the sprite. And another public particle system, which is going to be the death particles. There we go. And now we need to set the desk price and that particle. So I'm going to go back in here. I'm going to save this, save this back in here on the battle prefabs battle players, Let's see, Jimmy now has a reference to the death particles. I'm going to lock him down. Actually, I'm going to choose all. Let us just keep Jimmy leg locked down for now. And this is the death particles, I believe. And I'm going to add it into the death particles. So character death effect and the sprites, I'm going to go into the player, the death. And I'm going to choose this one. And for some reason it's not allowing me to add it. Maybe we should just make this a sprite. There we go sprite. And now this should be working fine where Jimmy prefab go. So for some reason this wasn't working, but anyways, no worries, we'll go back. We'll use the sprite, we'll save all of that. And now we have the that sprite and the deaf particles on Jimmy, and that's it. So we're going to go back to the Prefabs on the player's. I'm going to choose Draco and the grim. I'm going to go into the battle particles and I'm going to add the particles to them and that's brought should also be created. But for now, I'm going to issue you a challenge. And your challenge is to change these products. So first-off, you will need to create a method kill player. Then you'll need to check in it. If there is a debt sprite available, you'll need to access the sprite renderer component on the player and change to the debts pride, you'll need to instantiate the deaf particles. And finally, you will need to change it. Is that to true? So you'll need to change the characters is that variable to make sure that he is that to true. So pause the video right now and go do the challenge. Okay, welcome back. So we're going to scroll down in here and we're going to create a public void kill player. And in here we are going to check if we have a sprite. If we do, then we're going to get the component, the sprite renderer, sprite renderer. And we're going to get the sprite on the sprite renderer. And then we are going to set it to the debt sprite. Then we'll instantiate the deaf particles. We call them. Okay, That's particles. So the particles, we're going to instantiate them on the transform dot position, so exactly on the character and the rotation will be the same. So transform dot rotation. We'll save that. And finally, we are going to make sure that is that is that is that is true. We'll save that. And now we'll need to call this in the update battle. So we're going to go to the battle manager. And here instead of simply having this comment, we are actually going to check if we have the active character at the position I as a player. And the active character hasn't already been dead. So this means that if he is that then this one is false, then we won't access the method. We're going to call upon the kelp layer in the battle character. So as you can see, we check that he is in fact a player and that he isn't that already. We were going to kill him. So who was that done? We'll save that. We'll go back into Unity. And I'm going to use the magic of editing and create sprites for that Draco and that to run. So I'll see you in just a bit. Okay, welcome back. So I've said the skeleton, that sprite. I've said 14 Draco. So and here there you go. So you can see the sprite, what I did with Jericho as I did with the demon or Jimmy, I also rotated the sprite and I made sure that he's dead. So now everything should be ready. So we're going to save all of that. We're going to run our game. And before we do that, we need to make sure that the display and here on the game was a 1920 by 1080. Now we're on the game. We started the battle. We are going to just simply be attacking, attacking, attacking. And we're going to wait for one of them to die. Attack, attack, attack. Hopefully one of them dies. Okay, so as you can see, our character just died, but we didn't see the particles because I think the sorting layer was bad. Let's try this on other characters. There you go. So Draco died also. And finally we have Jimmy also. I think our enemies have also died. So there we go. We didn't even see Jimmy dying. So the last thing that we need to do is we need to go into the Prefabs in here and you can check out everything I did. It's not too hard. And we can even set the positions in here to be all 0. Save that. And we can even maybe move this sprite of the Draco if you don't like the way he set up up there, where is the renderer? The layers, the sorting layer will be on the battle characters. On the level one. We'll save that. Now let's try to kill one of our players again. Be okay, so one of them died. Again. There we go. These are the particles, you just solve them. We can make them a bit bigger. Maybe, maybe increase the scale to two-by-two. And I think maybe make them a bit white. So this might differentiate between when attacks and when one dies. And that's all, that's all that you need to do. I hope you enjoyed this video. I hope you're killing your player as well. And I really hope that you are using your own sprites, your own particle effects, delving deep because particle or facts are really fun, especially when you get to know what each of these components do. So for example, the force over lifetime, which I added on the y. So it moves up a bit, as you can see, when one of them dies, when, when they get instantiated. So I'll see you in the next one.
115. Dealing With Dead Enemies: Welcome back, My favorite game developers in this video, when we run the game, we had the big key. We use magic, lightning on the warlord, magic tentacles on the war Locke. And as you can see, he slowly fades because he just died. But not only that now when we try to attack with Jimmy, we use the purple tentacles. We only have an option to attack the major master because we cannot attack the Warlocks because he's dead. So we attack the mage. We kill him with one hit. We went and we don't have any victory, will do that later on. But for now let's handle the death of our enemies. I'll see you interested in. Okay, so now we've handled our player dying. It's time to handle our enemies time. What are we going to do about our enemies? We want to have something a little bit different than what we do for the player. So what we'll do is we're going to change the color of our enemies. Let me show you what I mean. If I go and choose Draco, for example, or let's choose Jimmy, the player. If I go to the sprite renderer and here and choose the colors, you can see that I can manipulate the colors I have. So if I click in here, you can see that I can change the red, which makes them very cool. By the way, I can change the green and I can change the blue so I can play around. So for example, if I make it all the way red, he gets more red. And finally, I can change the alpha on him. So we are going to manipulate these three colors and the Alpha in order to change slowly, the color of our enemies to read and make them also fade out slowly. How are we going to do this? How are we going to move towards the red color and the fading out? Well, thankfully we have a very nifty method, which is the move towards, and you can see in here in the description that it calculates a position between two points, but we can also use it. And this is the vector 3. We can set the current position, the target that we want to move, move to. And finally the max distance Delta. And it's the distance to move current per call. That means we call it an update. And as it moves, we slowly move towards this, if you want, is the speed in which we move towards that target. So let me stop talking and let us start implementing. We're going to open up the battle characters, whereas the battle characters, metal characters. And the way we're going to implement this is an update. So we're going to create update in here again. And we are going to check if we aren't a player. And we are that this means that we are going to fade out our enemy. So I'm going to write fade out enemy. And I'm going to create this method in here. So generate the method. What are we going to do in here? First of all, we are going to get a reference to the sprite renderer component. So we're going to get component, the sprite renderer. Then we are going to access the color on the color. And then we are going to set it to a new color. We're going to open up the brackets. We're going to hit Enter. And in here we're going to go ahead and access math dot, move towards. So as you can see, we have the current, the target, and the max delta. We're going to open this up. And in here we are going to access again the sprite, the component of this pride. So I'm going to copy this. I'm going to paste it in here. Oops, I'm going to paste it in here. And from the color, I'm also going to access the r. So this will make sure that we access the red component on the color. As you can read in here, this will be the current. So currently we are on the color or which is normal for our player. The target will be V1 F. Why are we setting it to one f? Well, because we solved in here that when it's red, it's completely to the right. So back in our code. And then we are going to have some kind of speed in which the color moves. Let's test out 0.3 F. And we're going to multiply it by time dot delta time. And if you don't remember what Time.deltaTime does it actually, there you go. The completion time in seconds since the last frame. So because we're adding it and the update, that means it's being called every single frame. If you have a very strong PC, the frame rate will be higher, so the fading could be faster and vice versa when the PC is bad, the frame rate is low. The moving towards where it works slower. So what we'll do is we'll use Time.deltaTime. So it's the same on all the PCs. And this is very important to do because when you build your game and other players use it, not every single PC is going to be the same. So you need to always make sure when you move something, a player or the color or anything inside of update to always make sure to use Time.deltaTime or to use fixed update. But for now we'll use Time.deltaTime. I'm going to duplicate all these lines in here. We're going to change from the red to the green and the blue. And finally the a, which is the Alpha. And we currently have the target in here for the rat as one, the blue will be 0. I mean the green will be 0, the blue will also be 0 and the alpha will be 0. We'll keep the speeds the same. And you can see that we need to remove the last comma. There we go. We save that, and we are good to go. But we also need to do one more thing. And that is we want to actually turn off the component on the enemy. So we're going to check if the component dots sprite dot color dot a is equal to 0. And remember this is being called every single frame. So we are slowly moving towards 0 and this component is different than 0 until the move towards in here finishes. So when it does become 0 and here it game object dot set active will be false. We are going to save that. And finally, we are going to create a method in here to kill the enemy. So public void, kill enemy. And this is just going to set that to true. There we go. And is that where is it also? Is that this public? No worries about that. We'll set it to true using a method. It's cleaner to always use methods. So now back in the battle manager, where do we check and update battle? So we're going to look for update battles. So in here, we check if it's a player and we are in debt, then we call the player. And if we aren't a player, I've just copy this line in here. So one of the characters has an HP of 0 and it's not a player and he isn't already dead. Then we are going to go to the active characters dot I, and we are going to kill the enemy. That means we are setting him to die. So we're going to save all of that. We are going to go back in our game now there is still a small problem in here, but I'll fix it when we see it. So I'm going to run the game. I'm going to start the battle. I'm going to use magic to attack or use lightning to attack. Who should we kill the war Locke, I think his health smaller. Magic, blue. Warlocks. Let me make this bigger. Magic. Lightning, war Locke. And there we go. As you saw, he faded away. How cool is that an history no longer is played, so only the major attacks. But the problem that I was talking about is that when we go ahead to attack, as you can see, we have the option to attack the wall OK, and click on him. We again attack, which is very, very bad if we try to use magic, we can also affect the Warlocks, which is again, very, very bad. So we'll need to go and fix that. How are we going to do this? Well, we are going to go where we open the characters menu or where we opened the targets menu actually. And in here we check if the enemy count is greater than I. And if the active character on the enemy is at position r, Because remember, and here we are going through the enemies. We've created the enemies list right here, which is a list of integers. So we can check for the enemies in the act of characters. So in here, enemies at position I, the current HP should be greater than 0. Well, we'll save that. We'll test this out again. Let me maximize on play this game is better when it's full screen, because the words are a bit small. So we walk around. We had the BP magic, lightning, war Locke, magic tentacles war Locke. And there we go, He dies. So now when we go to use magic laser, we can still see the war Locke. He doesn't attack, but we can still see the world luck. Why is that? And that's because after we set it to true in here, it stays true as we go. So we don't set it back to false. We don't turn off the button. So what we'll do is in here we're going to create an else. So else if we don't have an active character or the count isn't a greater, then we are going to get the target dot gameObject dot set active and we're going to set it to false. So we'll save that, go back into our game. So as you can see, game development is a process of building. You don't get everything. First time we run the game, we had dB key, magic, lightning, war locked, magic, tentacles, Warlocks, he dies, magic laser. We don't see the war-like anymore. We attack only the main page. So I hope you enjoyed this video. I hope you are finally satisfied that we are killing our enemies, destroying them, killing our players, destroying them. And in the next video we are going to be ending the battle and victory. So we'll add to that satisfaction that you already have. So I'll see you in the next one.
116. Victory In Battle: Welcome back, My favorite game developers in this video, when we run our game, we start a battle. We do some magic on the Warlocks, on, magic on, okay, so great, he died. Some magic on the major master. Again, some magic on the major master. Let's try to call him so he dies. We won. We go out. We can see that if we start the battle again, we'll notice first of all, that we destroy everything previously and we also have the mana in here already used. So we are saving everything. We are ending the battle correctly. So let's not waste any more time and let's get started. Oh, okay, so time to when? Time for some victory. Let's go ahead and end the battle. So we're going to go back and here we are going to scroll down and we're going to create a new method which is going to be an I and numerator or a coating. So it's going to be a public eye enumerator. And this will be the and battle 14. And in here we are going to do a couple of things. So what are we going to do? First of all, the battle that is active should be set to false. So is battle active? No, it's not. It's false. Then we need to turn off everything that might still be in there. So for example, the UI button holder dot psychoactive to false. Let's duplicate this, the target menu. So target, where does it get 0 target. Buttons, dot selective. So it's not a game object. Enemy target panel, false. Then the magic menu, the magic choice panel, the battle motors. So if we have any battle, notice, we are going to set it or set the text in this case to be WE one. So this will be when we end in victory and we are going to activate the battle. Notice. Battle notice dot active, Activate. There we go. Now we are going to yield a couple of seconds. So we'll yield return. New, wait four seconds. And it's going to be three seconds. I guess it's good. Next, we want to update the player stats in the game manager. So for example, let's say we wasted a bit of Health, able of HP, a bit of manna, and so on. We are going to change it. So we're going to create a for each loop in here. We're going to go through the battle characters, player. In battle, We'll call this variable in the act of characters. Then we are going to check if the player in battle as a player. And then we are going to again look through the player stats and the game manager. So for each player stats, That's the type. And the player with stats in game manager, dot instance, dot layer stats, so get player stats. And then in here we're going to compare the names. So if the player in Battle dot character name is equal to the player with stats, where's the, where's the player with stats? With stats? Dot player name. Yep, there we go. Then we are going to set the player stats or the player with stats with stats dot current HP to be equal to the player and stats in battle. Okay, so there we go, declare in battle, these variable names are very confusing. I should have probably changed them. So now we said the HP, we can also set the mannose so the current manner with the current manner that we have. Next, we'll need after we finish the for each in here, we are going to next go ahead and turn off the battle scene. So the battle scene dot set active to false. And that's almost all that we need to do. But we need to also make sure that we destroy the remaining characters. So as you remember, when we finish the battle, when we go to a, another battle, which is the same, we can see that the previous enemies are still there and sometimes maybe they can attack. Maybe they are added to the list so they have a turn and it really messes up our battles. So what we'll do is we're going to clear these enemies from the list by issuing you a challenge. So your challenge is to destroy all of the enemies. So make sure enemies are destroyed when battle is finished. And you can make sure to clear or make sure to clear. This is a hint, the list of enemies to avoid then coming back and the next battle. So pause the video right now and go do the challenge. Okay, welcome back. So in here, first of all, we are going to access the active characters and we are going to clear all of them. There we go. So we cleared all the act of characters, but this is not enough. We need to go in here and we need to destroy all the players in battle. So we're destroying all the players in battle. And finally, before we finish, we need to set the current term to 0. And we should also go to the game manager and make sure that our player can walk again. So again, manager dot instance dot battle is active and it's equal to false. Save that. And finally, we need to call this method. And when are we going to call it? While we call it in a couple of places? And maybe the text notes we want should be changed. Maybe it shouldn't be like that. But in update. So instead of printing, we won, we are going to start a co-routine. And that core team is going to be the battle co-routine. And also when we run away. So where is the running away? Close. Next turn, running away. Let me hit the F key run. Let's set the run. Okay, there we go, The Runaway. So in here we are going to go ahead and start the coroutine. And because we said the battle to false and we turn off the battle scene, we are simply going to remove those two. And instead we are going to start a coroutine. And it's going to be the end battle quality. There we go. We save that. Now back in our game. When we run, we're going to try to kill all of our enemies. At the B key, magic, lightning, war, log magic tentacles, Warlocks. Is that magic? Tentacles, the major master. There we go. And for something when not completely right, let's turn down, let's see if any of our stats changed. So we attacked with the Grimm. There we go. The current Mano changed. We attacked with Draco, the current Mano changed and the player. Whereas deep layer whereas the player, okay, So he is indeed don't destroy, has money. Current Mano also changed. But for some reason the maximum is 30, just 30. Something weird about that. Anyways, let's stop in here. You need to make sure that the current monarch is 1, 0, 0, 0. This is a big mistake, big no-no. We'll save that. We'll also maybe go to the player and apply the changes. Okay, so the problem in here is that we didn't have a co-routine. So maybe we shouldn't turn off battle scene as being turned off prematurely. Okay, welcome back, my fellow developers, game developers. First off, we should have made sure that we not only destroy the player in battle, because this will only destroy the battle Character Script on our players and enemies. So we need to make sure to write player in battle game object to destroy. This will destroy the entire game object. Second, we need to make sure that I've been here. I commented out all the debug log for the damages because I was using the bugs. And India, we need to make sure that we in update battle. When we start the co-routine, we had these three lines in here that set everything to false, but we already do that in here in the end battle co-routine. So there we go. We need to make sure to set this to false. Now, another thing I noticed while running away, we get this message we want, and we don't want to have that when we run away. So in here, I'm going to remove these two lines. Or you know what, maybe later on we are going to check for the is running away too. We have a, we have a variable in here for the is running away. Oh, we don't. So maybe later on we'll create a variable that is running away. We set it to true. And here. And if it is true, then we don't print out the we want and we'll do also different things in here. So I hope you've enjoyed everything is working now let's go back into our game. We run the game. We start the battle. And let's see, we use magic lightening on the Warlocks magic. Oh, he died. That's cool. Then we are going to use on the master mage, again magic tentacles, Nystrom age, he dies. We want, we go away. You can see that all of the characters are destroyed. We start the battle again. We don't have as much money as we had. So magic, lightning, war Locke, and he didn't die this time maybe previously that was a critical hit. So lightning make master at them, attack us. Let's just attack. They attack us. There you go. Draco dies. This one dies. Let's try to run away. There is no escape. Runaway again, there is no mistake. They attack us, we are almost blind. Please run away. There is no escape, and we all buy it and be lost. But we still don't have any game over messages, but we'll do that in the next video. So I hope you enjoy it and I'll see you in the next one.
117. Creating Game Over Screen: Welcome back, My favorite game developers. In this video, we are going to be creating our game over scene, and we are going to go towards it whenever all of our players had dy. So let's not waste any more time and let's get started. Oh, okay, so now we need to deal with the fact where all of our players die, not our enemies are players and we lose the game. So we'll need a Game Over scene and a game over screen. Let's go first of all and to our code and to the battle manager. I'm going to close everything off as I move up. Let's keep this open. This we'll close this, close and everything else. And we are going to create a reference in here, which is going to be a serialized field of type string. And it's going to be the game over scene. Save that. Now we're going to scroll down and create a core team that is similar to the end battle coroutine. So it's going to be a public in numerator and the gain, gain over coroutine. And in here, first of all, we are going to create a battle notice dot setText. There's going to be we lost. Then we are going to access that battle notice dot Activate. There we go. Then we are going to wait for three seconds. So we yield return and the new way for seconds, and we'll wait about three seconds again. Finally, we are going to set the battle active to false. And we are going to access the scene manager. Do we have access to the scene manager? Nope, we don't. So let's go ahead and add him in here. So Unity engine, scene management, save that scroll back down. So Scene Manager thought load scene, I wanted to go to the instance. I'm so used to always having an instance after a manager. So load seen and we are going to load the game over scene. We'll save that. And we are going to call this when all of our players are dead. So instead of we lost, we are going to start a co-routine. Start co-routine. And as the game over scene. And I pretty sure we might have forgot a couple of things in here. Oh, so game over that. I had the game over courting. Sorry for that. We can delete those three lines or you can keep them as a reminder of how we slowly progress using our code. So I really love these three sections right now the players is starting battle, the enemy, or the four sections and the ending battle because it really shows how we, it's not about just pulling on code and making it work and that's it. No, it's about the process always slowly but surely we update our code, we add new methods, we use new techniques, and we also issue new challenges. And your challenge is going to be to create a game over scene. So create a scene for the game over at a canvas with a bit of text and background, maybe at three buttons for the load less Save Main Menu and exit game, and that's all that you need to do. So pause the video right now and go do the challenge. And I will come back with everything already ready because, well, it's not very fun watching me doing this every single time. So I'll see you in just a bit. Oh, hey, welcome back. So how did you get all of that? So I just created again over set some background, added these three cool-looking buttons. And I can say the, let's say really nice game over screen. So now the next thing that we need to do is to go ahead and create a scene manager script in here. So we're going to go to scrip and where shall we create the game? Okay, In the managers. So C-sharp script is going to be a game over manager at Enter. Wait for it to compile. No, please don't open this up. For some reason, opens up automatically every single time, so it's over. We'll add it to the canvas. We can add it wherever we want. We'll save that. We're going to open up the script. And let's see what we are going to do in here. And before I forget the Canvas anywhere, where is it? Okay, So scale with screen size and we are going to make it 1920 by 1080. And there we go. We'll save that. Okay, so let's open up the script of the game over, and what shall we be doing in here? Well, first of all, we start, we are going to play a different song. We are going to turn off the player controller and all of that. So in order to access all of this, we are going to go back and we need to add a couple of managers in here that we've already set up. So in the prefabs, the old yo AudioManager, the game manager, the player manager in here somewhere should be set. So let's see the items level. Nope, we don't need that. Maybe the Canvas could be used in here. And this is a campus one. Change names. Where is the prefabs? We still need the player controller, so we'll add the player. And I think that's all that we need to do. We're going to save that. And now let's go in here. And the start we are going to access the old yo manager dot instance, dot play background music. And which background music should we be playing? Let's see in the music. Let's see down here the cave theme. And sure, let's play the dark amulet. I think 44 is good enough. There we go. As long as changes, we don't care what it is. The player dot instance dot game object will be set to false, the menu manager. Okay, so set active to false, false. The menu manager selected false. The battle manager, manager dot gameObject, dot sad, active to false. And then we'll need to create the two or the three methods in here. We'll remove update. We're going to create a public void, Kohut to main menu. We're going to create a load less safe public word, low, last, Save. And we're going to create a final method which is going to be the destroyer game session. And we'll fill it later on. It's going to be a private static because we don't want it to change anywhere and be the same every time destroyed game session. And in here we'll do a couple of things. So with that done, I'll see you in the next video where we will be filling all of these methods up if you want to start on your own, I do recommend that you do this. And finally, don't forget to make sure that we always commit our changes. So now the enemies fade out. As you can see, I forgot to commit one of my previous changes, so what I can do. So what was the previous video where we were ending the battle in victory. So that means that we don't want to save all of these. We simply save these three. We stage the selected. So this is not 100% accurate, but that's all you need to do whenever you forget to commit your changes. So now we, and the battle and victory with a couple of exclamation marks, we commit the changes now we stage all. But because in the next video we will be doing more stuff and finishing up the game over. I will not commit the changes right now. And I'll see you in the next video.
118. Loading Last Save In Game Over: Welcome back, My favorite game developers. In this video, we finally finished creating our game over. So now we run our game. We can go to the main menu, we can exit, but it doesn't work. Let me show you the other buttons. So we can quit the game, but we just have liquid game and we can load the last saved that we were n. So there we go. And not only that, as you can see, our follow cam now works perfectly. It doesn't just hang around. So even when we go to another scene, There we go. So this is working. Our camera is always following our player, so I'll see you in just a bit. Oh, okay, so let's continue on with our game over. So I'm going to go back in here and we are going to first of all, fill in the straw game session because it's the most important method that we'll be using in the main and so on. So we are going to destroy, first of all, the game manager dot instance dot game object. Now, I know we've said this all in here, but remember when we leave the battlefield and go to another scene, all of our managers are destroyed and they move on to the game over scene. And they're also a singleton pattern. So I just added this in here just to understand that these will be in the scene and we need to destroy them. So I'm going to go back and we are going to destroy the other managers. So we're going to destroy the player controller. So the already player script, again object. I'm going to duplicate this one also I'm going to destroy the menu manager. And finally, we are also going to destroy the battle manager. We're going to save all of that. Now let's go ahead and create the quick menu. So in here we are going to destroy the game session in its entirety. And then the scene manager, where it's going to scene manager, don't we have okay, so we don't have that. Scene management. Save that. So Scene Manager, dot low seen, and what should we be loading when we quit to Main Menu? Well, we're going to get a reference. So in scenes, the main menu, let's copy that, go back in here, paste it. So as you can see, I tried to write main menu with adding space while I shouldn't, so it wouldn't have worked and we would have no idea why. And finally we are going to do the load last save. So we're going to destroy the game session here also, and will also destroy or we've already destroyed, I wanted to say destroy the battle manager. We are going to load Scene Manager, Load seen, and we are going to be loading the loading scene. So what its name? Let's copy it. Copy this one. Paste it in here, add a semicolon, save that. And let's make sure that we have everything in the built. So we're going to go to the Build Settings. We have the main menu loading scene. Let's add the game over. And what else should we be adding? I think that's everything that we need. What's this, the game over scene or we just added it. Okay, great. We can also add the dungeon, but we didn't create a way to enter it from the Francine, so no worries about that. Or you know what, I think we do need to add it if we died during the game. So BuildSettings. Let's add the dungeon also in here, save that, go back. And let's test this out a bit. So I'm going to go into the Canvas. And here, do we have any variables that we need to set? Nope, everything should be working fine. So I'm going to save that. I'm going to go back. I'm going to run the game. So first we start off. We don't just go. Okay, so as you can see, we have some cool music playing. What do we have in the console? We have a missing reference, which is the battle manager because we haven't added the battle manager or we turned it off. So we can add the battle manager in here. And as I've said, this is just for testing the game over. We don't actually need to have these managers in here because when we die, we go to the game over none of these game objects are destroyed. Remember that? So I'm going to find the prefabs, the game, the battle manager game. Oh, now I just remember that in the dungeon, we haven't brief up our battle manager and I'm looking for it and we can't find it. So I'm going to Prefab the battle managers, save that. Go back into our scenes to GameOver. Go to the prefabs in the battle the manager at that, if that won the game. And there we go. So now we don't have any errors. So let's try to quit the game. This doesn't do anything. Oh, we haven't even assign the buttons. Okay. So Canvas, Let's see the MainMenu button, but does it do to give it the campus we just created the game over manager, and this is the main manual. So we're going to quit to main menu. And then we're going to use the quick game. We need a small method in here that just prints out. So public void game. And we're just going to debug the cloak. We've quit the game. Save that. And here we are going to application.rb quit. But obviously this is not going to work because we are not actually in the game. So I'm going to go back into Unity. I'm going to give the canvas in here. Quick game. And finally the load. I'm going to go ahead and assign the Canvas. Came over manager quit two main menu or no, this is load last save. Sorry for that load last save, save all of that, run the game. And now we can quit the game. So we've quit the game. Obviously this doesn't work because we haven't built it yet. So let's try to go to the main menu. There we go. We are on the main menu. If we want to continue. There we go. So we start off, but obviously you can see that we don't have the camera moving with us. But let's test out the load. Let's save. It should be pretty much the same. So we load, let's save. There we go. But again, the camera isn't working and this has been a problem throughout all of the course. How are we going to fix this? Well, we are going to go into the camera controller. So where's the camera controller and an update? So where do we have update? We're going to check, and here we're going to create a while loop. And this while loop is going to check if we have a player target. And if that player target is null, then we are going to keep searching for a player targets. So declared target is going to be equal to find object of type the player. So it will keep looking for a player. And if we do have a virtual camera, then we are going to set the follow on the virtual camera. Dot follow equal to the player target dot transform because it follows a certain position. We're going to save that everything is good. We're going to go back. We're going to run the game. And now when we load less safe, we should have our camera following the player. There we go. We fix a problem that has been around since we started the course. I promised you we will fix it. We did fix it. I always make sure to fulfill my promises. I hope you're enjoying this course. I hope you'll like me as an instructor. I hope you like the way we are building all of this. We can finally stage our game over. Stage all commit our changes. And if you do have the time and if you haven't already, please do leave me a review. It helps me out a lot and I'll see you in the next video.
119. Battle Rewards: Welcome back, my fellow game developers and this video, when we run our game, if we hit the Y key, you can see that we have experienced earned, which is 15000. And then we have the items reward, which is a golden axe, a golden armor, and some HB ocean. So let's not waste any more time. We even have the close button working. And let's get start. 0 case. So now we start battles. We cope players, we kill enemies, we end battles. We have game over, we have victory, we have everything. But What is the incentive to actually go and fight? The incentive is, first of all, finishing some kind of quest and second of all, getting experience and a couple of new cool items. So that's what we are going to do. So we are going to go into the Canvas. We are going to open up the scene. And here I'm going to right-click and create a new panel. So panel, and this panel is going to be the battle rewards, rewards. I'm going to make it opaque to the end. So there we go, and we are going to add the background that we're using. So I'm going to go to the sprites, you are elements and add the one we're using all the time. I'm going to make it a bit smaller and I'm going to shrink it down to just yea big. I'm going to add a button in here to close down everything. So go to your eye and a button. This button will be the close button. When working with you, I prefer to always make sure to call close button. So we know that it's actually a button in here. Looking at the hierarchy. I'm going to add a text Mesh Pro and here, and we are going to make this button a bit bigger, just like that about that. So the tax, we're going to make it as big as we can. Go to the button as the background. You're pretty much familiar with everything that I'm doing. So keep perspective. Make it a bit bigger. There we go. Set this to be in the middle. And I'm going to shrink down the text to fit in the little box right here. So there we go, that's about it. We're going to change the font for some reason. It always does. This doesn't allow me to choose from the first time. Make it bold, make it black. Make sure that this is close. Make it bigger, as big as we can. Maybe at the bottom is a bit too big. So I'm going to shrink it down to just about the size and make the text about the size. So there we go, we have a close button. Next we want to set up two labels or texts or whatever to indicate what we get. So what do we get from a battle? We can get a lot of stuff, but for now, we are going to, the first thing we're going to get is the experience and the items. So let's go ahead and create a text much proven here, which is going to be the medieval party. Bold black. And this is going to be the experience rewards or XP reward. I'm going to make this bigger. And the middle huge font. Set it up here. Maybe not that huge of a font. Going to make this a bit smaller. I'm going to go ahead and call this the XP text label. I'm going to duplicate it and put okay, I didn't duplicate that. I'm going to duplicate it. Thank you. And then I'm going to set 14 the items in here. So this will be the items reward. There we go. That fits perfectly. And this will be the items text label. I'm going to remove this. We are going to duplicate this one more time. And I'm going to make this a lot larger. There we go. And in here we're going to make sure that do should we be auto sizing? I don't think so. Let's not all size. Let's make it smaller. There we go. And this will be the, let's say XP earned. Or we'll just try it in here. For example, 99, 99, XP. There we go. Put a space in here and the XP text value. Let's make it a bit bigger. And then I'm going to duplicate the exp x value. And here, and this will be the items. The next value. Now, I was thinking of maybe putting up in here at this price of the items that we get, which I think is a much better approach to this. I'll document you do that, but it takes a bit of more work. We want to make sure that we have the fundamentals down for now so we know the items that we get. But as I've said, I do recommend you to go ahead and implement images in here. So I'm just going to write golden acts, silver acts, and HB portion. So there we go. These are our items. I'm going to make sure to fit auto size and this because we might have several items and they might too squishy, too big for our canvas. I'm going to make this a bit bigger. Okay, So there we go, That's all that we need. Now we need to create a script to manipulate this. So I'm going to go into the scripts. I'm going to go which folder should we save this in dialogue characters? Let's save it in the battle system. Is it part of the battle system? Yes, surely this. So I'm going to create a C-sharp script and it's going to be the battle rewards handler. Enter. Wait for that to compile. No, thank you. We're going to add that are attached to the main canvas that we have. And then we are going to open up the script in here. First thing we'll do is we are going to need an instance. So public, static instance or sorry, battle, reward handler instance. And we're going to serialize a field because we need the, the XP tax and the items text. So we'll need TMP parole. So everything I'm doing in here, I'm going through it a bit fast because while we know everything that these are nothing too special, text Mesh Pro, we've already done all of this. So XB, text and items text. Then we have another serialized field of type game object for the actual reward screen. And I didn't mean to duplicate that. Then we have a serialized field for the items. She has the reward items. So of types, Item Manager. And it's an array because we have several of these item and the reward items. And finally we have an integer, which is the experience that we get. So and XP, or reward. There we go. So now we need a method to open up the reward screen. So I'm going to remove the start and update, and I'm going to create a public void open reward screen. Let's call it. And we are going to take in two parameters. And here, one will be the integer for the XP and the other one will be a items manager array, which are the items earned, let's call them, and that's called this the XP earned. Then in here we are going to set the XP reward as the XP earned. And we're not actually going to set each battle from the canvas. We are going to call this method in here and set the integer and the items from depending on which fight we get ourselves. And we'll see later on in the next videos how we actually start battles that have their own enemies, which have multiple types of battles in them. So maybe we have different combinations of enemies in that battle with different rewards and different items earned. So let's continue on. I just wanted to set the mood in here. Maybe don't understand why we actually have this type of setup. And here we'll see later on everything will make sense. So we're going to have the reward items as the items earned. And then we'll have the XP taxed. Taxed to be equal to the experiment earned, but well concatenated with XP space, XP. Good enough. There's this bother us? Nope, Doesn't. And now we want to set the item stacks, but first of all, we want to make sure that it's empty. So items, text, the text is equal to empty. Why am I saying that? Because we are going to loop through all the items, get their names, and concatenate them to the text. What do I mean by that? So I'm going to create a forEach. This for each, is going to look through strings, the reward item, text, and reward items dot item B item manager. And now in here we're going to set the items text, text to have a plus equals. So because we have multiple items, we need to add the plus equals so they all concatenate, so the reward items. And we're going to concatenate it with a comma. So how will this work? Maybe we should add the comma beforehand. Let's try to add it beforehand. Or know what. Let's add a backslash t. And backslash d means backslash tab. So this will be some kind of a space, sort of, but a bit bigger or we'll just add a space. Why not? There we go, we save that. Let's go into Unity. But before we do that, well, we need a way to actually test this out. So I'm going to issue a challenge. And your challenge is to open the reward screen. So create an input and update, check for a key. When it's pressed, open the reward window and with the appropriate arguments. So this is a very basic challenge. Pause the video right now and go and do it. Okay, welcome back. So I always delete update, but that's only because we don't actually need it. We just want to test this out. So I'm going to check if the input dot get key down. Using the key code. Which key code, which he keycode that we use y, o sound scape, we use the Y key. I don't think so. So I'm going to use the Y key and I'm going to open the reward screen. The experience I'm going to get rewarded with as 50 thousand. That's very generous amount. And the reward items are going to be the reward items that we will be setting. And here for the campus. Now later on we should make this private, but for now we're just going to save this. We'll set it manually in here. So I'm going to go back into our game. I'm going to go to the Canvas. I'm going to, whoa, we have so much right now to close all of this down. So I'm going to give the XP text value, the items text value, the reward screen, which is the battle. Rewards. The earned will be set on its own and then reward items. I'm going to add three items in here, go into a lockdown, let's go into the Prefabs items and what should we get? We get a golden axe, we get a golden armor, and we get some HP portion. I'm going to save all of that. I'm going to turn out the battle rewards. I'm going to run the game. And now we move around. Let's make this bigger. Had the Y okay, the y isn't working. Why? Why isn't it working? Because we for some reason forgot to do something and that something is, and that's something which is the most important part. And that is setting the reward screen to active. Oh my God. And we also need to do one more thing and that is to apply the close button. So I'm going to go ahead and create a public void close button. And it will simply set the reward screen to false. That back in our game. Let's get the button. And these are really basic stuff that sometimes you might forget. So the where is it? Battle rewards, handler, close button, save that, ramp, a game. There we go. Hit the Y key. And it still needs something that we are not doing correctly. Or either that or my y impotent isn't working. We save that. We should have saved the 0. Okay, so the problem was, which is always the same problem. I turned off the canvas because I had it locked. I didn't read what I was turning off. Now, when we run the game, I believe that everything is working on a 100 percent fine. There we go. So we open this up and we can see that we have something very wrong. And that very wrong thing is that instead of setting the name of the item, so the name, the reward items, text dot item, name. We set it to, what type is it? So now we run the game for the last time, I believe. And it will be working. There we go, The Golden Axe, the golden armor, and the HP potion. So I hope you enjoyed this video. I'm going to change the color in here, four of the values to read. There we go. So now it looks, it should look much better. You'll see it in the intro. So I'll see you in the next video.
120. Giving Battle Rewards: Welcome back, my fellow game developers in this video, when we run the gain. And lest we forget, I need to do something in here and that is to set the close reward, save that, run the game. Started battle. Use the magic fighting on the war-like magic tentacles, Warlocks. Now he's dead. Now use the magic tentacles on the main master. We went again. If we look at the player, he had 36 current HP and current XP. I mean, and when we close the button, you'll see that he has 1000006. That's because he leveled up and we remove a bit of XP. And if you also go to the menu items, we can see that we get our rewards. So let's not waste any more time and let's get started. Oh, so now it's time to actually give out rewards that we get on flexed four. So to do that, I'm going to open up our scripts again and I'm going to go into the battle handler. And in here, I'm going to issue you a challenge. So your challenge is to add the expedient to the active players. You are going to change the close button method to close reward screen. You're going to loop through all the players and give them experience. And you'll also make sure to add the items in rewards to the lists inventory. So pause the video right now and go do reach Chaldean. Okay, welcome back. So we're going to change this from close button to close reward screen. So in here I'm going to start off by, before closing the reward screen, I'm going to stop this. Or know what we could have kept the clothes. We'll see what we do. First of all, let's make sure that for each player stats, active, player, and game manager dot instance, dot stats. And in here we're going to check if the active player dot gameObject is active in the hierarchy. Then we are going to check for the active player. And we're going to add XP to him using the XP reward. There we go. And then we are going to create another foreach loop That's going to go through the items in reward items. And we're going to access the inventory dot instance, dot add items and the items that we're going to add, the item rewarded, save that. Next we are going to set the reward screen to save active to false. So I don't know why I deleted up there. I could have just added it under here. And then in here I'm going to set B battle active to false. So they came manager dot instance, dot battle active to false. And why am I doing it in here? Aren't I already doing that in the battle manager? Where is it? So somewhere in here, there we go. I'm setting in here to false. But the problem is that this is what makes the character or the player and Jimmy keeping, moving or staying in place. So when I want to open the bat rewards, I want to keep a genie stale in his place until he, and I, Oops, I want to keep him in place. I don't want him to move while looking at the rewards that he got. So we'll save all of this. But now the problem is in the battle manager because we have a couple of things to change. And what are these? We are going to be calling the battle reward. Where are we going to call it? We're going to be calling it when we end a battle. But if we run away, should we be calling this battle reward? You get a reward if we run away. Of course not, that is not what we are looking to do. And also we don't want to print out the one whenever we run away, we are going to do something different. First of all, I'm going to go up in here, and I'm going to create a private boolean which is running away. And this will keep track when we are running away. Then an order to test this, we are going to create two other variables, which are going to be public and XP, reward, amount. And also another public items manager type array, which is going to be the Items, reward. And this is, you'll see why we're doing this. First of all, let's set the running away to true and we run away. So where do we run a way? We run away somewhere in here. There we go. We are running away. So the value, we are going to set the running away to true. And now we're going to go into the battle co-routine. And in here we're going to check if we are running away. Then we are going to make sure to set the battle to false. That means we are going to be able to run again and then we'll set the running away to false. And if not, if we're not running away, then we want to print or not print out. Actually, we'll get to that. The battle rewards handler dot instance, dot open reward screen. And we're going to sent with the XP reward amount and the items, amount, items reward, I mean, so that's why we created these two variables in here. We'll get rid of them in just a bit. But for now we also need to make sure that in here only if we are running away or only if we're not running away. Sorry, if we aren't running away, then we are going to print out that we want. There we go. So we've fixed that problem. We are going to save all of that and we're going to go into Unity. Let's make sure we did everything in here, properly, saved all of the, okay, so we're going to go into Unity, go to the Canvas, go to the menu manager, and this will be only a temporary thing to do. So where is it? Battle managers? Sorry. So in the battle manager, we have the items rewarded and the amount, let's say it's 2 thousand. And the items will be, let's just add a gold or silver or golden axe and a monopole ocean. We'll save that. We're going to run the game. We are going to start a battle, will try to win it. So lightning, war, Locke, magic, tentacles, Warlocks. He died. Magic tentacles may master. We won. So we go out but we didn't. We always forget to add a reference to the battle rewards or we're going to go in here. What did we forget to add? So the problem in here, if we double-click and it's telling us that there is no instance of an object. Now, why is that happening? Because if we go back and do battle rewards, we've created an instance. We didn't set it to this. So I'm going to create a start and here again. And I'm going to set the instance to be equal to this. Now we shouldn't have this problem anymore. I'm going to stop the game. I'm going to run it again. I'm going to look at the player, how much experienced the C have. 36. So I'm going to start the battle. Magic, lightning, war, luck, magic tentacles, Warlocks heats that. Magic tentacles. Mmh, master, he's dead. 36. There we go. We have within, inside the close button, let's sell it in here. And the Canvas battle rewards close button, Canvas, but I'll reward handler. Let's set it to where is it? Where is it? The close reward screen? So I'm going to go ahead, just declare 36 closed rewards screen. There we go. One hundred nine hundred and thirty-six. That's because we moved a level up. So now we've leveled up with our players. Do we have any items? Let's go to the menu. Check the items. There we go we get a golden axe and a minor portion which we can take on Draco. There we go. We've added some manner. We didn't use the close button yet, but that's okay. It's fairly easy. So I hope you enjoyed this video and I'll see you in the next one.
121. Creating Battle Zones: Welcome back, my fellow game developers. In this video, when we run our game, we have a battle zone in here. Somewhere. There we go, we have a battle zone. And if it's active on Enter, when we enter into it, you can see that we start the battle. Nothing happens yet, but we will continue on with that later on. But for now we need to create a battle type. Have different kinds of enemies that we can choose from, and different types of rewards, an item rewards and XP rewards and so on. So let's not waste any more time, and let's get started with our random battle. Oh, okay, So now the battle system is pretty much working fine. Everything has been set up. But the only problem is that our battles start with us hitting the beekeeper and that's not good at all. So what we'll do is we'll create an area that when we walk into it, it will start a battle. If we wanted to start the battle or if we press a certain key. So for that, let's go ahead and create a new script. And the script in here in the battle system that's Right-click. And this will be the type of battle that we have. Salts will be the battle type manager. And why are we creating a script? Because each petal we'll need a couple of things. First of all, it will need the enemies that we have. It will need the reward that we get an IT will need the items that we get. So I'm going to make this a non mono behavior. And I'm going to use this as a system serializable. We'll save that. And now we're going to create three variables. The first one will be a public string, and it will contain the names of our enemies. Then we are going to create a public and reward XP. And finally, we are going to create a public items manager array, which is going to be the reward items. So we're going to save that. And now we'll go back into Unity. Go to the scene and will create an area. So I'm going to double-click on Draco. Let's make the scene a bit bigger. And in here we're going to create an empty game object. Empty game object. We'll call this the battle zone or something. So battle zone at Enter, Let's reset its position. Double click on that. And I'm going to move that battle zone. And here I'm going to add to it a box collider. So let's add a component, the box collider 2D. And let's make it a bit bigger. So that's about the box collider that we want to have. And we're going to make it a trigger. We're going to save that. Now we're going to create a new script in here, which is going to be the battle, instantiate or hit Enter. For some reason, every time I create a script hit Enter it opens up the Visual Studio, will add it to the battle zone. And we're going to open up the script. So now this is not the, this is not the script that I was looking for. What? Whereas the battle instantiated. So let's see, battle notification. There we go. This is the battle instantiated that's added to the battle zone. And now we'll open up the script. And the first thing that we need to do is create a list of battle type managers. So it's going to be a serialized field. And the battle type manager array, it's going to be called the available battles. Enter, save that. And now I'm going to issue you a challenge. And your challenge is going to be to add some battles. So create three potential battles the players will face and with different enemies and rewards. So pause the video right now and go create some battles. Okay, welcome back. So in here we can add a battle and as you can see, we'll have multiple enemies and multiple reward items. So I'm going to add three enemies in here and three items. Now you might be wondering why we are using strings in here and not like we did in the reward. Items. That's because if we go back and to our manager and here, the way we create a battle, where is it? Where is it? Where is it? We start a battle. We add the enemies and they are of type string in here. Or where is it when we start the battle, the string is the enemies to spawn. So we can't use these or we can change even this one, which is a good idea. I do recommend you try it out. It's a very good way to learn how to deal with this. But for now, let's go ahead and how much experience? Or first, let's add our enemies. So we go to the Prefabs. Let's put this down. And the attack enemies or no, the battle, the enemies. So I'm going to add a blue face in here, a and a war Locke. And that's it. This is going to be some kind of easy battle. We get 100 XP and we get only one item as a reward, which is, we'll see what it is. First of all, let's add three potential battles at the enemies. So this, the second one will be a mage. With the blue phase. We can even add a nother blue phase. So we have two blue faces. The reward is 600 and the items will check in just a bit. And finally, the last potential phi that we have is a major master with a mage and a, another image. And this will be 1, 0, 0, 0, 500 XP. And let's set the reward items. So what the reward items to get in here? I think we get one. So I'm going to go to the atoms and what items do we get? We get some kind of silver armor. Then in, So this one is done. The second one, which is a bit harder, we are going to add one, golden armor and in a potion. And finally the last one, which is the hardest, let's add two HP portions. One monopole ocean and one golden axe. So we'll save that. And now we have three potential battles that we can choose from. Now, the next thing to do is to go ahead and go into our scripts. And in the battle instantiated or we are going to create a couple of methods. So the first one, methods I meant variables. So the first variable is going to be a Boolean and it's going to be checking whether it activates on Enter. So activate on and turn because we can create two types of battle zones. One where it activates immediately as soon as we walk into it. And another one that keeps a track of the amount of time a player spends in that battle zone and then starts the battle. So we're going to create a private boolean that's going to keep track if we are in area. Save that. So now we're going to create an entrepreneur enter on Trigger, Enter to D. And we're going to check if the collision.com tag, we haven't done this in a longtime player. Then we are going to check if we are activating on Enter. And if not, we are going to check the area to be equal to true. And we'll be starting a counter in the next video. But for now, let's just print out that we are or we, or start the battle. There we go. Save that back in Unity. Run our game, walk over to the battle zone. And it doesn't work because we haven't set it to activate on Enter, activate on Enter. There we go. We start battle when we enter. So I hope you enjoy it and I'll see you in the next video where we continue our random battles starting.
122. Starting Random Battles : Welcome back, My favorite game developers. So we've created a battle zone. First of all, it activates when we enter it. So I'm going to run and demonstrate how that works. So as soon as we enter the zone, a battle ensues and 2s and 2s, I'm going no, I'm not sure. And another option is that if we don't activate on Enter, we run the game. We have a time between battles to be won. So now when we walk around it for 1 second, we then start a battle. So let's not waste any more time and let's get started. Okay, so time to finish off with our random battles. We are going to open up the script in here and we are going to create a couple of variables. So the first variable that I'm going to create is a time between battles. And it's going to be the time between battles. And the second one is going to be a private float battle counter. So I thought this would be a great opportunity to teach you how battle counters work in general. So and start, that means when we started the battle, we are going to check for the battle counter and we're going to set it to some kind of random value. So random dot range. And it's going to be a time between battles times 0.5 f and a time between battles set 2 times 1, 0.5. So it's either a little bit less or a little bit more, adding or adding the half of it. It's not a little bit, but let's continue on now, an update, we are going to check for a couple of things. We're going to, first of all, let's create the update. We're going to check if we are in the area. That means we've set the area, an area to true. And where is it? And the player dot instance dot deactivate movement is false. So we don't want the player to open the menu and be stuck in there for the battle to start, we want to make sure that he has the ability to move around and that he chose to be in this battle zone zone will. And then we're going to check if we have an input that get axis rho. And if we have any kind of horizontal movement or vertical movement, then we are going to start the battle. So I'm going to go into the player script and I'm going to copy the input.txt is horizontal. And I'm not sure if you know what I'm doing in here. So I'm checking if there is any input on the axis, on the horizontal. And that means if it's different than 0, or if we have any movement on the vertical, that means we are moving inside of this battles on. If we're standing still, we don't want to start the counter. So if the movement on the horizontal or the vertical is different than 0, that means we are moving inside of the battle zone. That means the battle counter can start counting down from Down dot delta time. Save that. And then we're going to check if the battle counter at any point becomes 0 or less than or equal to. And why are we setting it to be less than or equal? Because sometimes, and this is a question I get often. Sometimes the battle counter while removing Time.deltaTime doesn't get exactly to the value 0. So what we do is we check if it's less than 0, then if it is, we go ahead and start the battle. But not only that, that means this condition will pass, but I hope you understood why we set it less than or equal and not just equals, equal to 0. So in here we are going to set the battle counter to, again become some kind of random range. So there we go. And then we are going to start a battle co routine. Or actually this should be start coating. So we're going to start a co-routine, open up the brackets, and I'm going to go ahead and issue you a challenge. So your challenge is to create the golden. So you'll need to create a coroutine. Started battles. Or whatever the name was said, the battle to active will need to create a random number to pick a potential bottom. You'll need to set the reward of items and XP, you'll need to wait a bit, get it were a bit. That means yield return, wait four seconds, and then you will need to start the battle. So pause the video right now and go do the challenge. Okay, welcome back. So I'm going to go ahead and generate the battlefield method in here. And it's not a, we need to make sure that it's an eye enumerator. I'm going to remove this line of code in here. And the first thing that we're going to do is access the game manager dot instance, dot battle is active, true? There we go. The second thing is I'm going to create a selected battle integer in here. And it's going to be equal to the random dot range. And it's going to be the 0, the available available battles dot length. So what this does, it chooses a random value between 0 and the number of available battles. So it's pretty much self-explanatory. We've already did a lot of random that range. Then we are going to access the battle manager and the instance. And we're going to go ahead and set the items reward to be equal to the available battles at the position selected Battle dot reward items or no, no. I mean, yes, that's it. The second one will be the rewards XPS or the XP reward amount. With the XP reward experience. There we go. And then we are going to yield to wait a bit of time. So yield, return, new wait four seconds. And how much should we wait? About 1.5, I think is a good time. We can change it as much as we want. Then we'll go to the battle manager. Dot instance, dot start the battle or battles start. Okay, So there we go. It's the battle start. We should send them the string of enemies. So the available battles on the selected battle enemies. There we go, we save that. And finally, a good thing to do is we are going to fade in. How are we going to fade in? I forgot what the method was called. So whereas the menu manager and fading, fading, fading words, the fading Start Menu. Scarred, good game fade image, so fade image. So I'm going to access the menu manager dot instance dot image method. So this will fade the image in and out. Good transition into the battle. And finally, we are going to add something in here where we are going to destroy the zone if we want after we finish the bottom. So I'm going to add a serialized field in here, which is going to be a Boolean. And we're going to activate the Activate after starting. And what this will do is after we started the game or started the battle, if we want to deactivate after starting, we are going to destroy the game object. That means when we finish the battle ended zone, if we walk back in that zone, we no longer have a battle there. So I'm going to save all of that. I'm going to go back into Unity. Let's save that. I'm going to deactivate and the time between battles is going to be, I don't know. Let's set it to one, save that, run the game. And that means we need to stay 1 second inside of the zone. So there we go. One second. And we didn't fade out. We should have started fading out. Can we use magic lightning on the main page so you can see and hear that that works. We need to fade out. How do we fade out? We have a fading out. Fade, image, public, void, fade out. And we're going to copy all of that. Let's go to the Canvas, checkout the image, what is happening in here, the animator. So open up the image parameters fading. Let's go ahead and create a transition on the way back. And this is going to be triggered by a and fading with no exit time with the 0 time between transitions. And we're going to make sure that we end the fading. We save that. Let's copy the string reference. Let's go back in here. And we are going to end up fading. We save that battle instantiate water. And where should we be fading out? We should be fading out as soon as the battle starts. So there we go. We start or no, we call upon the menu manager. Instance. Fade out. Save that back in our game. Back to scenes. Run the game. Go to the battle zone. Let's try standing in there. So if we just stand, nothing will happen. If we start moving. There we go. The battle starts, we fade out, and now we are in battle. Ladies and gentlemen, let's try to win, but I think it's going to be, take a little bit of time. Let's see if it has been destroyed. Where is it? So no battles on because we want to destroy upon impact. Let's try to not the activated. So run the game. Enter the area, walk around. There we go. Was it destroyed? Nope, the battle zone is still there. And the last thing that we want to do is if we activate on Enter, we haven't actually started that. So if we go back and instead of printing, we are going to start a battle co-routine. And we should have started courting first. So start coroutine, open up the brackets, close the brackets, semicolon, go back, run the game. Run the game. And now when we walk to the battle zone, as soon as we touch it, there we go, we start the battle. So I hope you enjoy, I hope you are enjoying, I hope you are committing your changes. We have so many commits right now. This is an amazing project that we're working on. We have a almost finished RPG game, but there is one very, very, very important component in any RPG game. And that is a boss fight. And that's what we'll be doing in the next couple of videos. I'll see you then.
123. Boss Battle: Welcome back, my fellow game developers. As you can see, we have one scary demon in here. So when we run our game, if we walk down in here, we walked through this edge, we can see that we have a demon, but it's too late. We have to face them. So I'm going to attack the boss dragon. He's going to attack back. I'm going to attack the boss dragon again. Let's try to kill him. I don't think is too powerful. We won the battle because we have destroyed him with our characters. So let's not waste any more time and let's get to creating our boss enemy. Oh, case. So time for some loss battles. I think this is the most fun and exciting part. So I'm going to add a boss right here and displays. But first of all, we need a boss. So I'm going to go to the sprites, character, enemies. I'm going to right-click in here and create a folder for the boss. And the boss that I'm going to use as this one. So I found this cool looking dragon with a bit of animations. I thought it would be cool if the boss actually had some animations. I'm going to drag this boss and here, and as you can see, he's pretty small. So let's go into these sprites. Let's make this 30 to apply. I think is all a bit too small. I'm going to make sure that Let's try 16. Apply that. There we go. So now we have a big, big boss. We can even make him a bit bigger, but for now we'll just keep him as he is. We're going to choose all of these and make them 16, ply, make them all. No point filter applied. And we don't need to do anything much more. Or we do. Maybe we need to go ahead and change this from the default to the battle character and will make him 1. Hit Enter. There we go. So now we have this huge, huge boss. Okay? There we go. So now we're going to set our boss around here, maybe make him face the other way. We can make this happen by setting these two minus1. And then we are going to change this to the boss battle. We're going to add a box collider to him. But this box collider is going to be not on the boss, but on the area right here where the player can walk in and trigger. So we'll set it as a trigger and we'll add a battle instantiated to this. And we're going to create an available battle in here. There should be only one battle, and we should have the enemies in here should be one enemy and the reward items, let's set the word XP to 3000. And we'll get, maybe let's see what kind of items we can get. Let's go to the prefab items. Of course we get gold, gold and a couple of HP portions. Let's see, let's add more HP portion, three HP portions, and two monopoles. There we go and get and golden axe, golden armor, three HP potions and to manage oceans. Let's save that. Now time to create an enemy. And how are we going to do this? Well, I'm going to use one of the already created enemies of the battle. I'm going to add the war lock right here. And I'm going to change a couple of things. So instead of warlord, this will be the, what should we call him the boss dragon. So pause dragon. I'm going to change the sprites to have a boss. There we go. So a boss sprite. And there we go. The max HP should be 1, 0, 0, 0, 0, 0. With a current age fee of 100, the current managers should be eight hundred eight hundred and twenty. I've been by mistake. Dexterity should be 16. Defense should be 16. Weapon power 60. Yeah, Sure. Armor defense 50, I think is a bit overpowered. The that sprite. What should that sprite be? Well, we can go ahead and use one of these plots or you know what? I think this one will be disappearing just like the battle characters that we have. What else should we have the deaf particles? Let's add that. So prefabs and let's see character. What's this attacking particles, the damage taken. Now, this something different. That sea battle manager, oh, there we go. So the character death, let's click on this one again. And this is not the Warlocks, this is the boss. Dragon prefab will change it in just a bit. Then we're going to add the character death effect on him. We'll save that. What else should we be doing? I think this is everything, oh, the attacks that he has. So we'll add all the attacks. He will have all of our attacks. You could create a special attack just for him. I recommend you do that. So let's see where do we have the attacks in the battle? Nope. Okay, so I found the folder. Let's click on the boss battle. And oh, I meant to click on the boss dragon. And let's see what he has. He has the loo fire. Okay. So we needed to show that we lock them down. So we have the slash, the blue fire, the tentacles. Let's give him the laser that's given him the purple tentacles, and let's give him the lightening effect. So there we go. Now we have a very strong boss dragon. What else should we be adding to him? I think that's pretty much enough. So I'm going to go to the battle characters. So I'm going to see battle prefabs, enemies. I'm going to drag in the boss and we'll create an original prefab. There we go. So now I'm going to go into the boss battle. I'm going to remove the boss Dragon 4. Now, the boss battle, let's see. The enemy that we are up against is the boss dragon. Whoo. So scary, he really is kind of scary. We don't want to activate on Enter, because usually bosses, you can still run-away before the battle starts. But we'll see that if the battle already starts, there is no escape for us. So I'm going to set the time to be two. I'm going to make sure that the active on Enter isn't active on Enter. So I'm going to increase the size. And here too to do, I'm not sure that. And I think that everything is almost done. So now if we run our game, Let's try to walk into that zone and see if the battle starts. So there we go. Okay, So apparently not so well. Okay, so the idea in here is that we don't want our battle character, I mean the sprite to be a battle character. Let's just set him as a player. He will be rendered normally, will move him a bit to the right. So I'm going to, unfortunately the sprite is already here. So if I move it, the box collider will also move. I'm going to put him in here. I'm going to adjust this. There we go, save that. And we also need to make sure that if we go into the battle characters and I mean the battle manager and the enemies prefab, we need to add the dragons. So I'm going to lock down the battle manager. I'm going to go into the enemies at the dragging. Let's save that. And let's try to walk over there and see if that works. So now the battle starts, and there we go. So we have that huge dragon against us that we are or should be ready to fight. Now, the next thing we need to make sure of is that we cannot run away when it comes to the boss. So I'm going to issue you a challenge, and your challenge is nowhere to run. So you'll need to create a variable and t battle instantiated that decides whether this is whether we can or can't run away. Do the same and the battle manager add a Boolean argument to battle start method that will decide if we can or can't run away. And finally, set the variable and the of the battle manager. So pause the video right now and go do the HL7. Okay, welcome back. So in here we are going to create a serialized field. Let me just separated from the rest. And it's going to be a Boolean and it's going to be can run away. And then we'll create a private Boolean type bool on all this should be in the battle manager, which we're going to check. So in here we're going to create a private bool and it's going to be the can run if we can or can't run. Now in the battle start method, we're going to add another parameter which is going to be the Pool can run, save that. And now we're opened up. And in here, if the battle isn't active, we start the battle. And we said the can run equal to or less than it, can run away, is equal to the can run away. Save that. Now we're going to scroll down into the runaway method. Whereas the runaway method, there we go. And we are going to set a condition around all of this. And we can only run away if we can run away. So I'm going to add those two. And I'm going to move this if statement and side. So if we can run and the value is greater than the, I mean, we should move all of this. There we go. So if we can run, then we are going to check if we have a chance of running away as we are going to go to the next turn. And if we click on the Run away button, it will not work because if we are against some kind of boss, and the last thing that we need to do is to avoid any errors. So here's a nifty trick in here. So you can see that the start battle is now wrong because we need to add an argument. So a very nice trick you can do is go in here. You can see that we have two references. If we click on them, there we go. We can see we have one in the battle Manager Instance start battle and one and here so we can double-click 0. So we are in here in the battle instantiated. And this battle instantiated or has the can run away. So we're going to set it as can run away. And the second reference is on line 50. 50. This is the one that we've set. Second one is on line 73 and here, and let's set it to true. Can't run away just for now. We're going to save all of that. We're going to go back into Unity. Will wait for this. So the boss battle in here. There we go. So can we run away? No, we cannot run away, but in the battle zone, we can run away. So I'm going to save this. I'm going to run the game. And you can add some kind of message or notification, which is a good idea. So I'm going to start the battle. Let's try to run. Nope, we can't let us try to attack him with lightning. Let's try to attack him with everything we've got. There we go. He killed us, N1 hit, let's try to attack the dragon. That's very scary. So we have a very powerful demon. We want o, we killed him. Nice. So we defeated the dragon. We got golden axe, golden armor, HP, HP, HP potion, potion and mono potion. We can even create something in here that makes sure that if we have several manipulations, we can add like a small parentheses with a a3x next to them, and so on. We can even turn off, whereas the activate upon entering. So now if we walk around in here, we start the battle again because we don't the activated after we start in here, there we go to activate. This should always be on for boss battles. And there we go. That's all that we needed to do for our battle won battling a boss. In the next video, obviously, we need to create some way of completing request when we defeat enemies and especially bosses. So I'll see you in the next video.
124. Completing Boss Battle Quests: Welcome back, My favorite game developers. I always say it with the utmost intent, with all my heart, my favorite game developers, you've made it this far. When we run our game, we can see that we have a question in here that is defeat the big jag and boss. If we go down, we start a battle. Let's try to kill him as fast as possible. The attacks on the sky are so weak. So let's try to kill that dragon. Again. Magic, lightning, drug and magic tentacles, dragon, magic tentacles, boss Dragon. We went, we get our rewards. When we click the Close, you can see that the element five, which is the defeat big dragon boss, is ticked and we finished that quest. How cool is that? So let's not waste any more time. Let's See you in here and let's get started. Oh, okay, so we want to be completing some kind of quest when we defeat the boss. How are we going to do this? First off, we're going to go into our battle instantiate water. And in here we are going to create a couple of variables. I feel like every single video I start off the same way. Anyway. Let's create a serialized field. Do something outside the box. So this is a Boolean and it's going to be called the should complete aqueous or quest, just quest. So when this is ticked, this means that when we finish this battle, a quest should be completed. And we're going to create a public ring, true ring quest to complete. And let's save that now back in the battle to rewards. Whereas the bad too. Why don't we have the battle rewards here ready for us? Rewards, rewards. There we go. The battle rewards notification. We're going to create two variables in here, which are going to be a public bool, mark, quest, complete, and a public String. The quest to complete. Save that. And now we can scroll down when we close the reward. In here, we're going to check if we have the mark quest complete. Then we are going to access the request manager dot instance, dot mark quest, complete, mark quest incomplete or complete. And in here we're going to send him the quest to complete. So this is I remember how the quest manager works. I'm not sure, but thankfully, we've named our methods to suit the needs of what they do. So now we know that we mark this quest as complete. So now back in the battle instantiated and one of our coroutines. And here, when we start the battle, we are going to call upon the battle what was called rewards handler. There we go. Dot instance, dot, dot instance, thought Mark, quest complete should be equal to the should complete quest. So should we complete a quest? And the second one, it's the quest to complete will be equal to the quest to complete that we have in here. So if I double-click, we can clearly see that Let's do one and the battle instantiated. And this one is indeed battle rewards handler. We are going to save that. We are going to go back in here. Where did we save or quests in the game manager, I believe came manager, where all the quests there we go. I'm going to add one and here, the feet, the feet. Big dragon. Boss. I'm going to copy this. And I'm going to go, where should we be going with this? And to the boss battle? And we should complete a quest. And this will be the quest complete. I paste it in here, I go, save this. I'm going to go in here and we make sure that we don't think you should complete the small battle or we can test it out in here. So I'm going to save this. I'm going to run our game. I'm going to go ahead and check in the game manager. And here, first the game manager, game manager. So we can see that we have the defeat, which is the fifth element in here. So I'm going to go to the boss battle. Wait for the boss Attack, Magic lightening. Let's try to kill this boss. And again, that's make the big tentacles. There we go. Magic lightening boss dragon, blue boss Dragon. This was such a weak attack. Let's try the purple tentacles on the boss dragons. So we one, Let's see. Now we get to see our rewards. When we close, we should see that this element is complete. And there we go. We finished one of the quests that we needed to do. How cool is that? So now we've completed everything I hope you enjoyed. I think this is the last video of the course. I'm not sure. Maybe we'll make another one, maybe I'll update this. But until then, I hope you enjoyed everything. I hope you left a review. I hope you like me as an instructor do let me know. I would love to hear your opinion.