Learn Unity Engine and C# by creating a real top down RPG [FULL COURSE][C# Unity Tutorial]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to a very long video so what you're about to see right now is a re-release of the course that i've made back in 2017 about making a top-down rpg game that course is actually um it's three years old but i believe that the content in it is kind of still relevant because back then i was using tilemap and tilemap was recently new so that's the most uh prominent thing that we're using um the reason i'm re-uploading this is for this whole purpose that it's been a thing fully is now on udemy and um i don't have access to the account unfortunately so it's not really being maintained and um there's better chances that people are going to be replying to the comments here then on my non-existent udemy account and that's it so if you have any question of course post them in the comment section down below as mentioned it's quite a long video so try to put a timestamp as well for the question so at least if you ask something away um and i have a timestamp i can go back to that part of the video and remember a little bit what was going on back then uh so you can either do that here in the comment section down below which i would appreciate or you could also go to the discord and ask us question there which is also something i would appreciate so um if you guys enjoyed this or it's a one time off by the way but if you guys enjoyed this please subscribe to the channel helps us quite a lot and by all signing me i'm rebuilding the channel so i'm really um i'm really digging those number anything that you can give me is really appreciated a like a subscribe and a share sharing would be good all right i think i'm done promoting myself um enjoy the course cheers hello and welcome to the very first lesson in which we will download unity 2017. if you already have the engine installed make sure that you are at least on version 2017.2 or beyond that is because we are going to be using tilemap a new feature in this latest version so in order to download this you will head over to unity3d.com and click on get unity now if you want to make sure that you are on the same exact point as this course is right now the latest version is 2017.2 if in the future you're on 2018 you can head over to this link over here unity3d.com get unity download archive and then you can choose manually um the version we're going to be using for this course however i don't think there's going to be any problem using a version in the future all right so once you're on the ut store they're going to ask you which kind of download now we don't need anything else but the personal version the personal version is going to allow you to release game on mobile to monetize from it the only uh little thing though is if you have revenue over a hundred thousand usd a year then you're going to have to upgrade to say um this plan over here which is their best sellers 35 per month but in our case since we're not making any money at the moment we're going to try the unity personal version if you scroll down and you accept the terms you'll be able to start downloading the installer the installer is not unity itself it's really just a small file that is going to connect to the internet i am going to run it right now and this will download the version you want to have so i'm going to click on next accept the terms now when you get here this is where you choose what component you want to add on top of unity of course you're going to want to have the engine itself so unity 2017.2 mono develop and unity debugger is really really useful in case you don't have one already in my case i do already have one i'm using visual studio but i'm going to install this anyway um the documentation is of course something that you'll want to have and then standard asset is something i don't really take those are assets that they give to you free asset you can use in your game to get started really quickly and do some prototyping example project i don't need that and now the other component our component you can install anytime later but since i know that in my daily life i do create game for android i'll be checking this also ios and also webgl because i build for those three platform on a daily routines that's just something on my end but in case you plan on making game for different platform you're better off just installing them now once that's done you're going to click next few times and wait until the install is completed once this is completed you're going to have guaranteed 2017.2 install on your desktop computer quick note the reason why we're using unity 2017.2 is only so we can use the new tilemap system which is a really really fun to use system in which you can just paint the ground with your tiles and it creates a level so it's something really really fun to do and it's going to save us a bunch of time after about five or ten minutes of downloading install you'll be able to launch unity by clicking on the finish button okay so now we have the engine installed every time you open up unity you're going to be seeing this screen over here this is a list of all your project on your hard drive and if you're logged in you're even going to have project in the cloud but in your case if it's your first time you're not going to be seeing this now what we're going to do is make sure we hit the new button over here and create a project now we're going to have to give our project a name i'll give it top dungeon name for top down and dungeon for whatever it is we're going to be doing i'll make sure to put it on 2d as well now my location is going to be on the desktop and everything i'll be doing in this course is going to be put on my desktop for the length of this project let's go ahead and create the project and launch the engine if it is your very first time using unity i really suggest that you take the same exact layout as i do so you know where i click and you know where everything is based on what you'll see on the screen now to do that to achieve the same layout as i usually have i'm going to go on the top right over here and click on the default button and i like to use a tall layout something like this i just pull all the window like this i have as much scene space as i can and here you have the hierarchy inspector and project i'm going to right click on project and make sure this is a one column layout this is how i'll be working for the rest of this course if of course you have a different layout and you've been using unity in the past use that use your own layout is going to be way more efficient for you but if you never actually use the engine before go ahead and copy this exactly out this is going to help you see where i this is of course gonna help you follow the course at a faster pace okay so now let's do a quick recap of what these screen do scene view is your scene view so everything you do everything you put in your level is going to be seen here and this is actually where you make your whole level now the hierarchy is a replica of scene view but this one is really just focused on data so inside of your scene at the moment there is only one camera and you can see that camera is here as well if you decide to move it you can see the value at the top here with the position value you can see it change so these two are linked together the scene view and the r key now whenever you select something just like i've selected this camera right now you're going to have some extra information on it in the inspector window so when i select my camera as you can see we can tell that it has a transform a camera a flare layer and also a audio listener and this is all on a single object which is the main camera if we are to create a empty game object you're going to see that it has nothing but a position in the world and we can move it the same way we move the camera inside of the scene view now to actually mess around with the transformer a little bit to mess around with the position i am going to create a cube displayed right here in the scene view and i'm going to press w by pressing w you're going to have to move gizmo and you'll be able to move it the same exact way we have been moving it for a while if you press on e you'll be able to rotate it either on a single axis like this by clicking on the lines or on multiple axis by clicking in the empty here you can then press r to play around with the scale those are really basic controls and we are going to be using them as we make our level later now the final one the final window i'd like you to have a look is the project window now the project window is the exact same replica as the asset folder in your explorer let me actually get a little bit deeper on that if you right click inside of the project window you can see there is a button called show in explorer let's open that up you can see that this is in my desktop and it is in the top dungeon which is our project folder inside of it there is couple of things that you need to have unity working while the engine is running you need to have the temp folder there is also some project settings saving you know different things such as the project version um the input manager all that kind of stuff that we need to have the game working some library of course to work with the code and finally the asset folder and this is the one that is going to be the most important to us let's open up the asset folder as you can see it is empty right now i'm going to create a random file so just a random text document as you can see hs txt document nothing in it let's head back into the engine you're going to see that it is now in our project as well kind of useless at the moment but i just wanted you to know that the asset folder is the same as the project window as seen over here so we're going to delete this thing and start creating a folder structure that we'll be using for the rest of the project the first folder we'll be creating is one called artwork and inside of artwork i'll be creating a folder called animations and another folder called levels that's it for artwork let's go down create another one for prefabs another one for scenes and another one for scripts those are all the folders we'll be using during this course now like i mentioned in the intro we're going to try and keep this as small as possible as simple as possible so you guys can go back re-read the files figure out where they're connected and also reuse them in the future if you'd like to create more content for the games having that said we're going to be ending this up by creating a new scene that seems going to be the main scene in which we're going to be doing a lot of testing at first and eventually turning that into some kind of hub so what we're going to do is make sure we have a clean scene at the moment i only have a main camera so this could be considered as a clean scene now if you put more stuff in it i encourage you to just hit control and n on the keyboard which is going to create a new scene make sure you don't say this one start again from scratch this is a fresh new scene and now you can click ctrl n s to save i'll be calling this one main and i'll be drag and dropping it inside of the scene folder what we've done here is we created a new scene and we saved that new scene you could have also done that through the file menu by clicking on new scene and then save scene okay so we have our ui setup we're going to be messing around with the ui a little bit later on as well because we're going to need more window in the future such as the console that we'll see eventually which is here and also the dial palette and probably more that i don't really have in mind at the moment but we'll be playing with the layout a little bit in the future make sure that you find one that you're comfortable with and also make sure that your layout has at least the arrow key the inspector the project the scene view and also the game view hidden somewhere alright so that's it for this lesson i'll catch you in the next one where we'll find a texture atlas so we can build our own game around that texture atlas see you there welcome back everybody before we start and dive right into the engine and just get everything started starting to create code starting to design levels we're gonna need some kind of art now i encourage you to go ahead and make your own art but if you don't have any if you don't know how to make art if you don't have any knowledge in photoshop or how to make sprites i encourage you to go get this one right here that's the one i will be using during this course it is free and also royalty free which mean you can download it for free of course there is no cost and then royalty free means you can use it inside of your commercial project if you wish this is something i really appreciate is someone from itch.io and he upload his own um he called a 16x16 dungeon tile set so this is what we'll be using and um in the end this is what you see right here it's only one texture it is called a texture atlas so that's a 256 by 256 pixel picture and in that you're going to crop what you need so that's exactly what we'll be doing inside of the game engine in a little bit now if you'd like to use the same exact tile set as i'll be using for this course then go check out the resources tab in your lesson and you'll be seeing a link to this tileset make sure you download it import it in your project this is a simple png image all right so once you have the texture downloaded i have it right here on my desktop you're going to either drag and drop this right in your project or you're going to put it inside of the asset folder because you know that this project over here is the same exact thing as the asset folder so i'll be opening up the top dungeon that's my project folder and i'll be heading into assets and i'll just drag and drop this in here if we go back in the engine you'll see that it just appeared okay so what's inside of here let's actually rename that to atlas that's going to be our texture atlas this is how we call these atlas because it contains more than just one object in here that we'll be using so i'll be taking this and drag and dropping it into the artwork folder okay now let's have a look at what happens if we double click on it since it recognizes a png image it is going to open it up in your favorite photo viewer so throughout this course we're going to be using most of the left side over here to create level so imagine we're going to be splitting those quiz one by one and we'll be painting at levels using those we're also going to be using the little red goo over here um that's going to be some kind of healing fountain the enemies are going to be at the bottom left your player sprites are going to be at the bottom over here and also the weapons will need the weapons we'll also be using one of these boss here one of the three boss and also doing a sprite animation with these torches and the chest so basically we're going to be using a lot of that when we create a level we won't be using all of it so in the end if you want to make that texture even smaller you'll be able to crop what you want and just put it in a smaller texture but 256 by 256 is very very small in the first place so this is a really good really optimized texture and that is going to conclude it for the very first section this one was super simple we just installed unity we set up our ui so it looks the way we want we're basically ready to work and that's exactly what we'll be doing in the second section guys so join me there we'll be talking about moving an object around moving a sprite around and doing manual collision detection see you there welcome to the second section of this course by the end of this section you're going to have a moving character that manually detects collision with either the wall or the other enemies and also you're going to have a camera that follows them around so let's get started right away by opening up the artwork folder the first thing we'll need to have a character moving is to actually have the character on the scene somewhere so this is our texture right here we're going to click on it make sure it is under sprite to the new eye now i'm looking at this in the inspector so this texture we import the png image make sure it is under sprite to the end ui and then hit apply if it wasn't already once it is completed we are going to go under sprite mode and make sure this is on multiple the only reason we are doing this is because this specific atlas right here this specific image has multiple sprites on it so we need it to be on multiple if you cropped out your player if you have a different texture and your player is scrapped out into a single image don't worry about putting it on multiple you just need to have it in your project somewhere in our case our player is somewhere at the bottom here so we still don't know which one we're going to be using but this is a multiple spreadsheet so go ahead and hit apply once more and we're going to then click on the sprite editor this is going to open up this nice window and in that window we're going to manually crop out our player so i'm going to pan around using the middle mouse button and then zoom in again using the middle mouse and i'm gonna choose which player i like the most in that so we could start with that little boy over here that little disturbed boy and i'm going to make sure that i zoom in very very close and i click and hold to drag around so as you can see it's going to create that green that green square and make sure you wrap the whole player around it including the little outline over here so once you have your first drag make sure you resize it properly in this case i have something that is 15 by 16 and that would be our player right here if you'd like to have something that is a little bit more clean and have a standardized size for every single sprites we're going to have i really suggest you put that on 16 by 16 by extending this thing by one pixel so when you look at the bottom over here you're going to see the width is 16 pixel and the height is 16. now you could of course have something else that is 256 by 256 if you have um more definition in your sprite but in this case all the characters all the little players you see here can be fit in a 16 by 16. maybe at the exception of this one um the knights they're a little bit bigger but if we want to use all the same size of the player we can go here and as you can tell they all fit in a 16 by 16. okay so i'm going to go back make sure that this one is the one that i selected and i'm going to go down here really important you go down here and you rename this sprite this is gonna be player underscore zero once we have more sprites for the player i'll call this one playerunderscore one player underscore two and so on actually let's do that right now so we're going to once this one is completed one once this one is clean so 16 by 16 we're going to do another drag just by clicking anywhere else and i'm going to select this little guy as well this one is 16 by 15 so i'm missing one in height so let's get that and here we go that would be player 0 and that would be player 1. so i'm going to make sure i rename this one as well okay so at the moment we have our two player sprites they are not registered just yet we have to click apply at the very top and that will conclude all we need to do today with the sprite editor if you close that up you're going to see that your atlas now has this little arrow if you click on it you'll see player 0 and player 1. you can also have a preview of those sprite by clicking on this at the very bottom of the inspector as you can tell you see this is our 16 by 16 pixel player one and player zero okay so last episode what we've done is we created some player sprites using the atlas they are right here that's player 0 and player 1. i am going to go ahead and drag and drop player 0 anywhere in the scene as you can tell it's fairly fairly small and you can just drop it wherever you want but if you want it to be centered what you can do is just drag it inside of the r key remember that the ir key is just a text and data representation of what's inside of the scene so as you can tell here we have our sprite it is a little bit small so while the atlas is selected we are going to go up here in the inspector and change the filter mode to point so no filter and you'll end up with something like this alright so we fix one problem now another problem is the fact that this is very very small to show you exactly how this looks in the game i am going to pull this game in the window and just make sure i anchor it on the left like this so i just click and hold and i put it here you can also give yourself a proper size now what i like to do before i start developing any game is to choose for which type of resolution am i going to be building this in this case we're making a standalone game now for standalone games modern game would go for something like 16 per 9 so in 1920 by 1080 that is way too big for us since we're using pixel art that is only 16 by 16. if we put that on a very very large screen in hd this is not going to look good so what we'll do instead is we'll make a game that feels like the old one so something more retro i will go under the game section over here and instead of having the free aspect like we have right now free aspects mean as long as you resize the window it is going to match we are going to choose our very own aspect so here i have 800x600 which is a really common resolution for old games in case you don't have it there you can click on the plus sign and manually add it by typing in 800 by 600 alright so now we have a fixed resolution it looks somewhat like this but it is still way too small what we need to fix next is the camera we're going to click on the camera and then open up the camera component and then we have to make sure that our projection is orthographic this should be set by default if you decided to create a 2d project if you'd made a 3d project it should be on perspective and it is going to be not really good for us this is not going to be something we want we don't want to have any perspective in our game since we are 2d since we are flat so let's put that back on orthographic and then i'll put the size on one having a size of one is going to make it so every 100 pixels you have is going to be equal to a meter so technically if you'd like to stack those player one on top of the other you can duplicate this by clicking on control c control v and then changing the y axis to 0.16 and it is going to stack perfectly on top of the other one all right so we pretty much fix what we had to do the next step is going to be to start coding the movement of this player okay so in this lesson we are going to start coding and if you've never coded before i made sure that the class is really really small in terms of scripting but in case you've never coded before make sure you actually follow copy every line one by one and leave some comments next to it i will be explaining what every single line does what you'll have to pick up if you've never coded before is just how to read the code and in which order which we'll go over really quickly once we start coding okay so let's click on our player over here and let's add a component now this is where you would choose what kind of company you want to add unity has a bunch such as the box slider 2d which we'll need in the future but we'll want to create our own so i'll type in player and there is a couple over here i don't want any of those player is going to be my own custom script so let's go under new script press enter once more we're going to be coding in c sharp of course and then you should see that a new script has appeared it is right here in your project folder and is also on top of the player if for some odd reason it is not on top of your player make sure you drag and drop this right here and if you have two of those you don't want that to happen either so right click on one and remove component alright so if we're ready we're going to double click on player either here or down there this is going to open up your default script editor if you've never coded before and you just start using unity this is going to be model develop for you in my case i'm using visual studio 2017 and either one you're using is going to look something like that with maybe different color in the background um and you know just different interface but what we're really looking for is the code so i've mentioned earlier that i'm going to show you how to read the code and in which order to read it so if you've never seen a script before you might have a little bit more ease doing so once we're done with that explanation but i also don't want to bore the more advanced user so what i'll do is i'll create the script i'll make the player move and then at the end of this lesson i'm going to go over how to read the code so if you already know how to do that you can skip then until then we are going to be creating that script so for this player to have manual collision detection we're going to need some more information from the outside and that outside is going to be the box collider so we're going to need a box collider i'll start by declaring a private box collider 2d that i'll just call box collider now notice that this one is private so i can't drag and drop it in the inspector i have to manually get it in my code and i'll do that in a private void start so instead of the start statement i'll say box collider is going to be equal to get component box collider 2d which means if we are going to have the statement run we're going to need a box collider 2d on our player like a hundred percent sure if we don't have that our script is eventually going to crash because we'll be using the box collider what we can do is head at the top here and do a require component type of box collider 2d this is something that could work for you i really don't like it so much i don't have the error because this what happens when you put this is that you're going to manually create one on your player as you can tell right now it hasn't compiled just yet let me just delete that drag and drop here as you can see it put a box slider 2d manually there but i also like to resize my thing most of the time so i don't really like having the require statement i'll go ahead and i'll remove it and if we do end up forgetting to put our box letter 2d well we'll have no reference on that and we'll know exactly what's wrong that being said if you do not have a box collider 2d on your object just yet now is the perfect time to get one by clicking on add component box color 2d and make sure it is the size you want it to be so in our case we might want to click on the edit collider and just make this a little bit smaller on this end really depends you could also go for something even smaller than that say the error is not going to count in the collision so something like this could also work and let's get rid of the video as well so this hitbox is really going to be for the player to move around and also when he receive hits all right so once that is completed i am going to lay down a private void i would do an update but since we're using physics and we're using the manual collision detection we're gonna have to do fix update and this is going to update every time actually fix update is going to follow the same frame as the physics so this is really important we are on fix update in this very specific case if you're looking for inputs i usually don't like doing fix update because sometimes it might skip one it's really really rare but sometimes it might skip some inputs but in that case we really don't have a choice since we're using uh manual collision detection we'll also have our own formula that use physics okay alright so what i like to do in a movement update loop like this is to make sure i have one vector that is going to keep track of the delta movement every single frame so i'll go at the top here i'll declare a private and that's going to be a move delta move delta means in between this frame that i'm rendering right now and the next one what is going to be a difference in between my position and where i'm going to be so by the end of this frame we're going to be adding our player's position our player's current position with the move delta and we'll end up where we want to be this sounds a little bit weird like that this sounds maybe a little bit complicated but we're going to make sure it is not so much at the very beginning of our movement loop i'm going to make sure i reset the move delta this is in case well actually this is so on the new frame so the frame after the one i just explained we are going to just go back to zero we might not have any input anymore so we can say move delta is equal to vector.0 so we start off fresh at the beginning then we're going to look for the inputs on the keyboard and add them up to the move delta to do this i'll declare a float x that's going to be my delta in x and we'll get that from input get raw axis or get access raw with horizontal so make sure this is a string we call that horizontal get access raw is going to return you -1 r1 or 0 so it's going to return you minus 1 if you're holding a or the left arrow key it's going to return you 0 if you're not holding any keys and it's going to return you 1 if you're holding d or the right arrow keys the reason i know which key i need to press to receive those result is because they are set in the input manager and we can find it under file or sorry edit project settings and input if you go in the inspector now check the axis out and if you click on it you're going to see that the negative button is left so that stands for the left arrow key and the alternate negative button is a positive is right and alt positive is d so you have your wasd set up in horizontal and vertical and you also have the arrow key set up as well so we're using horizontal and vertical for those reasons now let's do the exact same thing with y so we're looking at get axis raw this time we're going to be using vertical and we now have our input left and right again i'm going very slowly this time just so we can actually give some help and give some uh room for the new people that are trying to understand but let's do a small debug.vlog i'm telling you this is not going to be as slow in the future but just to make sure we can understand what's going on here let's do a debug.log with x and just be needed we'll do a debug.log with y back in the game if we go under window we pull out the console i'm going to anchor the console down here since we have plenty of space now that we have a 800 by 600 you're going to see that every frame we have zero zero in this case and if we hold a you're gonna be seeing minus one if we hold d you're gonna be seeing one if we hold a and w you're gonna be seeing minus one and one so as you can tell the inputs we get are really based on our keys and i'm just changing those by pressing on either the arrow keys or the wasd all right so enough easy stuff we're going to wrap this up make sure we put that in a single little vector here so we're going to move this at the top here and when we reset the move delta what i'll do is i'll just put those uh directly in here so i'll do a new vector3 x y and then zero this way we create a new vector3 we also reset it at the same time so when we say reset the move delta that is also true because we use those values here that we were going to put inside of the move delta anyway now we just collapse a little bit of code next thing we're going to do is swap the sprite direction whether we're going right or left so let's actually do that right here in common swap sprite direction whether you're going right or left to do this it's going to be fairly simple so we'll take the input if move delta dot x is bigger than 0 if it is bigger than 0 let's make sure that the transform the local scale is going to be equal to we could do a new vector 3 1 1 1 which is the current scale it is on right now or we could also do to save some memory vector 3.1 because this one is static and it is already declared else actually we have to do it else if really important here so else if move delta dot x is smaller than zero we'll do a transform local scale and then we can do here a new vector three minus one zero zero so we're only changing the scale from one to minus one uh depending if we're going left or right now the reason i did the else if statement here and not just a else is if we are on zero because here this is only if we're above zero and that's only if we're below zero if we are on zero it means we're not moving on x and we don't want to be flipping to a default um orientation so let's see what's going on in here when i'm pressing on d the player stays the same if i press on a you're going to see that e disappear so why is that exactly let's actually find out we're going to click on player and we know we're modifying the local scale so let's have a look at this number here at the top this is when we're pressing right so that's vector 3.1 because it's 1 1 1 and where we're going left we do get the minus one right but then there is zero in y and zero in z which means we just don't see this anymore as you can tell if we just scale this up you're going to start seeing the player so what we did in the code is we pretty much just shrink our player to a really really small state where we can we can't see him anymore right so let's go back into code and correct that mistake here we go small test again really quick that's right that's left right left and so on so we've got the position right now we have to make this thing move so let's go down and say make this thing move very simple we can do a transform dot translate and then translate using the move delta and we're going to make sure we do it times time the delta time this is really useful because if your game is running on a really low end device it's going to be running super slow and if you're running this on a very fast device say let's run that's running that at like 120 fps then your player is going to be going faster on the faster device and slower on the slower device which is unfair for the two person playing the game so if we do a time.delta time we make sure to make that equal on both devices okay let's give this a try now our player moves left right up and down as you can tell we're going to be adding a lot more in the next episode as we do the collision detection but at the moment that is all we need to make our player move and i will now go on and explain how exactly the code is read so this is going to facilitate the new user but in case you already know everything that's going on i do encourage you to step on to the next lesson alright so let's talk about code flow a little bit we won't be able to show you everything you need to know here because unity hides a lot of it so a lot of what's going on in the background a lot of how the code is supposed to run normally is actually hidden behind unity which makes it really simple to pick up at the same time but you're not going to understand everything you need if you've never done code before especially if you've never done chart before now let me explain to you um two things here everything you see over here this is a function and everything you see over here this is a function these two are different from the variable declaring at the top here or i like to call them fields now these in this very specific case are special function what i mean by special is that we really didn't have to do anything to have those runs so at the beginning of your game this was run and then every single frame this was run so every single frame it was checking for input it was assigning the move delta it was swapping the sprite and it was making the player move this was happening every single frame and we never told anybody to do that this is what unity does in the background if you actually match the function with the exact same name as what gave you the callback they call it this is going to happen automatically there is a couple um that you can call the beginning like start this is only random once there is also a wick you can tell that those are special because they turn blue when i finish completing it so if i do awake like this if i just make a mistake this is going to be valid it's still going to be in the code i won't have any error but this won't run at the beginning awake is a special call from unity and this is something we have to respect now if you type in start like this this is also not going to work because the one that unity has as a capital s at the beginning as you can tell it now turned blue now why is this important this is important because later on we're going to be creating our own function something like private void on collect coin so once we collect a coin we do something but those one we're going to have to call them manually so say if we want to run on collect coin at the beginning of your code you could go ahead and just put it down here now start is going to make sure to call it once it's done with all it needs to do i'm going to go ahead and remove these and have a look so code is read simply from up to down once you enter a function you're going to have a look at the first line then the second line then the third line if we went ahead and we did something like this you're going to have an error as you can tell we have those little red underline that says cannot use local variable x before it is declared and that is because at this point in the code when it's running the fixed update loop it says move delta is equal to x y and zero but x does not exist yet x only exists on the other line of code this line and at this point it's already too late so you have to make sure that if you're using something it has to be declared first or has a value which is also why we reset the move delta every single frame it is because we're using it down here one quick thing before we go ahead and we close this very very gentle introduction to the code flow is we're gonna have a look at the top here for the variables so variables are are actually declared this way so you start with the accessibility of your variable whether it is a private or public protected there is a couple we like private the most because it cannot exit the class player so right now nothing nothing outside of player could access move delta or box collider so this is just the accessibility then you go ahead and you declare the type and the type is a bunch of things so type could be a lot of different thing at the beginning when you start coding you learn about int you learn about float you learn about strings now a little bit later on you learn that everything you create every single class you create also becomes a type so i can say private player and as you can see it turns on with the right color it just gives me the right to declare a variable of my own type and that is pretty much it i can't tell you much about that because we're going to get into really complicated explanation which is why if you have a background in code this is going to help and if you don't just tag along you're going to pick up some skill as you copy and paste just like i did in the first place alright guys in the next episode we're going to be having a look at collision detection cheers welcome back to another lesson in this one we're going to be going over collision detection and we'll also start creating our walls and also another npc we'll put in there just so we can test our collision against other objects and other npcs or enemies so we're going to start off by actually creating those walls and also that npc for that npc we can simply use the other player drag and drop him in here make sure he does not have the player script and we're just going to move him say right about there make sure we also have a box collider 2d2 so this is really something that we need this one needs to have a collision as well and here we go so we have player one that has collision i'm going to rename this to test npc this way we don't confuse this with the real player and then we'll need some walls in terms of walls what i was thinking is we can go back inside the atlas and start cropping just two pieces of wall let's go in the sprite editor and let's take whichever one we want i am thinking about this black block over here so i'm going to go ahead and make sure i just take this from the top and make sure this is 16 by 16 which it is right now so i'll call this one wall 0 hit apply and let's go ahead and grab another one maybe this one this is basically the color of the floor so i'll grab this one as well this one's gonna be floor zero so we have the floor which is this color and then the wall that's gonna be black again i hit apply and let's set back okay all right so later on during the course we're going to be dealing with tile map and the new tile editor for unity 2017.2 that's going to be quite cool but until then we're going to have to place them manually so i'm going to stack these on top of each other perfectly just like it would be in the uh tile editor and i'm also going to make sure that these two walls at the same time they have the box collider 2d on it now i will go ahead and take the floor drag and drop it right in here and i'll just place it somewhere close doesn't have to be perfect and i'll also make sure to stack this one 0.16 above i'll copy it once and just put it here on the left and once more like this as you can tell we're totally overshadowing our our previous npc so now what we need to do is we need to start creating some sorting order and also some collision layers so let's start by looking at the sorting order of the sprites i'm going to click on player and have a look at the sprite renderer component this is what is actually rendering the image you see as you can tell this is our sprite now on this you're going to see that there is a sorting layer and this is what we have to play with so click on it add a sorting player and i'll call this one if we click on the little plus sign we can call this one um humans or creature or whatever you want so let's go and call this actor later on we'll have more such as items and weapon and a hitbox object but right now all we need is humans or actors sorry so under sorting layer for the player i'll be putting that on actor make sure we do the same exact thing for the test and pc and as you can tell it is now going to pop on top of this i'll be leaving the wall and the floor on default layer so that's perfect for what it does right now remember that we do have colliders on those wall but we don't have collider on the floor we don't need any collider on the floor we'll just be able to run freely on there now what we have to do next is we have to split the collision layers and that is really important for a few reasons um the first one being you don't want your player to run into other npcs or actors and you don't want your player to run into walls but it could technically run on top of a switch which also has a collider and it could technically run on top of say ealing fountain that also has a little trigger area where you get ill so you have to choose what you actually get blocked from and will be blocked from what we call blocking objects and also npcs or actors so we're going to go ahead and create those two layers right now to create a layer i'll go on the very top right here click on add layer and that layer is going to be blocking and for the user layer 9 we'll also add something called actor once you do have those layers they are not applied automatically so you have to go back on the walls and make sure you select both walls put that on blocking and then go on the npc and on the player at the same time and put that on actor this is something we won't have to do for every single wall in the future we'll have everything covered under the title map of course alright so now that the game is properly set up we have both players and a tsm pc on the actor layer and the walls on the blocking layer we're going to go ahead and open up the player script once more and do a lot of modification here our current problem right now is of course that the player goes through anything it wants including the blocking layer so we're going to go back in our code and inside of the code we're going to declare a field at the top called the raycast hit 2d i will just call hit this one is going to be used for for us because we're going to be casting our players collider box where it should be in the future and we'll check are we allowed to go there and if we're not we're simply not going to move so let's sneak in between these two calls right here and go right right in the middle and we'll say hit is going to be equal to a physics 2d box gas and we're going to be doing a box gas in our current position so transform the position with the box collider.size and the angle is zero since we never really rotate our player and then we'll do a direction on here so the direction is where we're supposed to go in the future now we're only going to be doing it one axis at the time in case we need to only move one axis at the time so we'll do new vector 2 0 and let's do move delta y first so up and down first and now the other thing right here is distance to get the exact same distance as we would in the translate we have to do the time the delta time as well so let's do mat f that absolute we're going to start by casting this since this is the distance you don't want to go in a negative direction we're going to do move delta dot y times time the delta time this is going to give you the distance and finally um this is either result but in our case we're going to be using layer mask instead to know which layers are we testing this against and we said we're going to be testing this against actor and also blocking so we have to do something that's going to regroup both of these layer masks together we can do layer mask get mask and now this takes in a param so you can you can put as many layers as you want in here they are denoted as string so the first one is going to be actor and the second one is going to be blocking wrap this up and we finally have our very very long um function called for the box guess now if our boxcast did hit something that means that we can't go there this is impossible we hit something that's either on the actor or on the blocking layer and we don't want to overlap so if hit dot collider is equal equal to null that means we can actually move since we haven't hit anything collider is null we did not have any result on our boxcast that means we are allowed to move and now we're going to take this bump it up here but as you can tell we've only tested against the y-axis so we have to change this a little bit instead of doing transform.translate with this we're going to do transform.translate and it takes in this right here so instead of passing him a full vector3 like we do right now we can pass him three floats instead so let's go ahead and do that first one is going to be 0 we're not moving on the x axis simply because we only tested the y axis y is going to be move delta dot y times time the delta time and finally z is also going to be zero great so we have what we need right here let's make sure we add a little bit of comments at the top here make sure we can move in this direction by casting a box there first if the box returns null we are free to move this is for the y-axis let's duplicate this copy and paste and do the exact same thing for the x axis so same as before but instead of doing a new vector 0 and move delta y we're going to be doing move delta x and then 0. change that for an x and if we do end up moving then of course move dot x 0 for y and we should now be good to go so let's have a look at what this gives us during the game now you're going to see that the player doesn't really move it doesn't do anything we wanted to do so it completely stopped moving which means that every time it tries to cast doing a box gas it always hits something even if we're going in the right direction there's nothing on my right why does it still collide with something well the reason is quite simple it collides with himself because himself is on the actor layer as well and this is needed because the other enemies we don't want them to go through the player so if we put our player on something else such as default you're going to see that now he moves so the only reason that he wasn't able to move in the first place is because he hit something on the actor layer as you can see right here now of course we don't want that we want to make sure the enemies actually collide with the player so what we have to do is turn off the game and head under the headed project settings and change something inside of the physics 2d so under the physics 2d there is going to be a bunch of things you can mess around with you can mess around with the gravity you can mess around with a lot of different things but what we're really looking into right here is this queries start in collider so we want to turn that off to make sure that our player ignores himself as you can tell right now our player is right here he's on the actor layer so he's on the one we need him to be and if we press on play he's now able to walk so he totally forgot about himself he's not no longer colliding with himself but if we go and check this npc out as you can tell it's blocking and i'm still holding a so i'm still going left but i'm not blocked from moving if i decide to go up and as you could also tell the wall is blocking me as well so if we do go ahead and just for testing purpose we create a box collider on this floor this floor is currently on the default layer if we go on it we actually walk right through so this is perfect this is exactly what we needed and this is why we use different layers alright guys so this will conclude today's lesson i hope you enjoyed we did some manual collision detection and we'll have to work on it a little bit more later on when we create weapons and the combat system other than that i will see you in the next lesson where we'll tackle a really really simple camera hey guys welcome back to another lecture in this one we'll be having a look at creating a camera that's going to follow our player around but we'll make sure to give it a little bit of twist a little bit of interesting factor what we'll do is we'll draw a squaring off screen just like this and if the player escapes that square then we're going to move the camera so this is not just a normal camera that you could attach to your player and just leave it there it's going to be a little bit more interesting and also a little bit more customizable so let's go and create a new script on our camera we're going to click on it head over to inspector and create a camera motor i like to call it camera motor because this is what will be driving the camera movement and since we're here let's also take these two new script we've created in the past episodes and put it inside the script folder now we're going to open this one up and double click on it in our script this time we're going to need a couple of things the first one is going to be a public field so a public transform that are called look at this is basically just going to be the player we could also use this value later on to put focus on some other object in the scene that is not necessarily the player but in our case today we're going to be using look at as if it was the player we are then going to create two public float one called bound x and one called bound y now these are the square i was talking about how far away can the player go in x before the camera starts swallowing him i'm going to go with a very small value such as 0.15 now let's do bound y and this one is going to be even smaller because if we move on the y axis it should be a little bit faster to snap all right so now we have our value it is time to write our algorithm in the update loop so let's go ahead and say private void update now update is not going to cut it just like we had to do a fixed update for everything physic based in our player we have to do a late update for everything that is camera wise the reason is really really simple late update is being called after update and also after fix update now if we actually move our player in the fix update if he is not standing still he's going to move then we have to make sure that we move the camera after he's done that move because if we do it the other way we're going to experience a very very small desync that is going to be quite annoying to the user's eye as logic is concerned just think about it like it's a normal update okay so we're going to start by declaring a vector3 i'll call desired actually i call it delta just like the player this is going to be the difference in between this frame and the next frame so we're going to start by initializing it to vector 3.0 we will first start by checking if we're out of the bound on the x-axis by having a float delta x and this one is going to be the look at vector dot position dot x minus the transform.position.x now when i use transform.position.x you have to think that this is the center of the camera so the middle point where our camera is this is the focused area right now and what we do is we get the distance in between that focus area and the player if this is bigger than bounds x it means we're outside of the bounds so we're going to go ahead and have a look right here by doing an if statement if delta x is bigger than bound x it will mean that we're outside of the band towards the right but this can also happen on the left side so we're going to do a or statement and say delta x is smaller than minus bound x this will mean of course that the player is on the left side and it's outside of the bound now in here i do a or statement but then i have to check whether it's left or right so i can add the proper value and we do that by doing if transform.position.x is smaller than lookat position position.x so we check which one is on the left and which one is on the right here we check is the center the focus area the middle of the camera is that smaller than the lookout is it smaller than the player if the focus of the camera on the x-axis is smaller then you look at position at x player's position in x it mean that the player is on the right and the focus of the camera is on the left so we're going to add on top of the delta position so delta dot x is going to equal delta x minus bound x just like this else it means we're on the other side so delta x is going to be equal to delta x plus bounds now this is to check if we're inside the bounds on the x-axis we're going to duplicate this copy all of that paste it and we'll do the exact same of course for the y axis so i'll just be swapping those x four y's including the bounds i'll use capital letters here and just change every x you see for a y there we go let's have a double check that seems good to me we can collapse that and collapse this and finally we have to move our camera so we'll do a transform dot position is plus equal so we're adding on top of our current position and let's just add delta dot x and delta dot y and of course 0 for the z axis we don't want to be moving on the z axis ever and you always want to be at something like minus 10 we are at right now because if you're too close even though this is orthographic if you're too close you're going to hit the near clip plane and you won't even see your thing anymore as you can tell right now i'm playing with my z value so by default we are on -10 and we're going to keep it that way okay so now we have our main camera that has the camera motor on it and it has every value filled out except the look at now i said this is a transform so we want to be taking the player transform by simply click and hold and dragging it in the lookout field this way you'll see the player 0 pop up now let's actually start the game and see how this looks we have our player we go up and down there is no room in the x-axis sorry on the y-axis but you can tell that there is some room on the x so we have some playing space right here and if we get too far away the camera starts following us but if we just play in the middle like this it is not going to bother us and i just realized i've done a typo right here on the last very last line this is delta dot y and not delta y now back to my game we now have that little room very very small amount of room in between the x-axis and the y-axis you can also modify those manually right here in the inspector as the game is running and that is because our fields are public so what if we try something like 0.3 in x and 0.15 in y so we have enough space in y i believe as far as x this is also fine to me so i'll be rolling with these new values 0.3 and 0.15 when you stop the game however those are going to be reset at what they were before the game started so i'll have to reinput them manually when the game is not running all right so that should conclude it for the very second section of this course in the next one we'll create an actual level and from there we'll be creating objects we'll be creating some enemies we'll be creating a combat system i hope you tag along because the next one is using the new tile map editor and it is gonna be quite fun so guys i will be catching you there hey guys welcome to the tile map section in this section we're going to be creating different rooms for the game the first thing we'll be doing is we'll get rid of all these nasty floor and also walls that we've been putting there just for testing purpose now we are going to create them using the awesome new tool unity has for us it's called title map now to do this we are going to need some tiles so we're going to go under the artwork folder click on the atlas again and we're going to start sketching out some more tiles we can use so right now we have the wall 0 and the floor zero we're gonna need some more of course you can use all of them if you want but i will be going over very specific one that we will be using for the gameplay like this one over here this is gonna be a healing fountain that we can use in the game now what is really amazing with this atlas right here is that everything is really 16 by 16 so everything is made out of blocks are 16 by 16 like this over here the healing fountain is something we'll be using but as you can tell it's a little bit weird we take all that empty space but this is something that uh is required so we can have um this piece right here then that piece right there another piece that also has some floor on it this is going to be really useful when everything needs to be placed next to each other and we'll give this a try so the first one right here is this block i basically cropped a 16 by 16 starting at the very top here and like i said it looks like it doesn't make any sense right here because we take so much empty space but everything is going to be made out of 16 by 16 blocks so this is actually required let's go ahead and go down here say healing fountain and this is going to be underscore zero because there's going to be multiple part to it so let's go just benated make sure we do the exact same thing so take a 16 by 16 block again just like this and this is going to be the healing fountain underscore one and finally one more time 16 by 16 so healing fountain two so here we go we have this right here so let's see what else we could have i'm thinking about cropping this at the top here all of this part actually including this oh sorry including this and have this as a whole object but like i said everything has to be cropped in 16 by 16 so i'll go ahead and go to the very very top here and start slicing those one by one always making sure i have 16 by 16 down here so we'll be calling this wall underscore 1 because we already have wall underscore 0 which is this black here and we're gonna keep on going like this i invite you to crop as much as you want of course the more you have the more you can make your level look good in my case i'm thinking about grabbing this then grabbing some floor different color for the floor like the one you saw down there and maybe the crates and after that i think we will be good to go and then after that we'll also grab those right here just to create some kind of animation see how that works and how we can change sprite over time but now for the moment i will go back to slicing these making sure i always have a 16 by 16. so i will keep on cutting this and i will be right back in a moment all right so at this point i have all of these they're all 16x16 and they are all named properly so i'll go ahead and get the exact same do the exact same thing i've done but this time for these floor right here make sure of course you don't move the ealing fountain at all so this is going to be floor 1 and i also just realized that my naming convention is not constant and that's not something you want to have so as you can tell here everything starts with a small letter but for the healing fountain i think i took some caps so let's go back and change that healing fountain written this way and this was one and this was too all right so we're gonna feel better about ourselves later on for that so i'm going to go ahead and start cropping all the floors okay so now we have the floor as well we have the explorer clutter here what i'll be doing is i'll head over here to the top and also get those stairs but i don't really feel like having two extra space at the top here but as you can tell they are above the line so i think we'll be cheating just a little bit and um grab one less pixel in this down there let's actually see if it works so i'm going to create my first air and that's my second one this one is 16 by 16 we get all the color we need and that's how we're going to be cheating this one a little bit so let's call it stairs zero this is stairs one and let's get the other side as you can tell this is really something you can play around you don't have to follow all the rules you don't have to follow the rules that the creator put you can just do whatever you want at this point you crop exactly what you need it's starting to look good we could go ahead and crop some more i'm thinking about the pillars down here and also the pillar up here they're a little bit different one of them has a wall and the other one doesn't so i'll go ahead and grab those and the crates as well so i will be back once that is completed alright so now we have the pillars and also the crate the final thing that i will actually do right here in this cropping session is i'll grab those torches one by one this way we can actually use them and animate them later on so i think those are also 16 per 16 so let's just make sure we do a 16 per 16 square and try to match it perfectly where it would fit um everywhere and as you can tell this is not really you know this is not fitting in the 16 by 16 would have to actually move one block like this and have two of those sprites every time we have one torch which is not really fun at this point so what we'll do instead is we'll create our own size for it so i'll go say right here in the middle grab the highest point and that is something like 15 or 12 by 21 so we'll be using this size instead for every single one of these let's go ahead and put that one at the beginning i'll call this one torch zero like i said we're making our own rules at this point but everything has to be 8 by 21 in this case so that's 8 by 22. let's change it torch one and so on and so you get the whole idea behind this we're just remaking the rules behind this very specific torch all right so we have a pretty nice sprite sheet with a lot of nice sprites on it we make sure to cut everything so it works so everything is 16 per 16 which means we'll be able to use it pretty much anywhere in the tile map for the exception of these little torch here in case we feel like we do want to have them in the tile map which we totally we don't have to do that like if we don't want to do that we can also just put them on top which is something i think we'll be doing in the end um since those one are going to be special and animated but if we actually want to use them in tile map we'd have to revert to using something that is more um well that is 16 by 16 as you can tell you have the square space to do it so you can actually use this go up to 16 so that one is 16 by 16 and just drag it down here as well it's really hard to see because it's really really light but you have the space to do it this guy that made the texture is you know pretty good at making sure everything was blocked in 16 16. now after all that hard work make sure you hit apply we're going to be taking this instead of the game engine and you'll be seeing all of that spawn inside of the atlas so something quite big guys so in the next lesson we are going to open up the tile map we're going to set up a tile map in our scene and start designing our very first map so at this point we should pretty much have a lot of little sprites we can use in our tile map so a lot of little tiles that are all 16 per 16 at the exception of those torch we'll do something else with that in the future so we're going to go ahead and open up the tile map by going under window tile pellet so this is where we'll do most of our work now we also need to make sure that we have a title map in our scene right now but before that let's take our tile palette and anchor it somewhere i'll go and anchor it down here where the console is okay now let's head over to the arrow key right click and create a new 2d object tile map this is going to create you a grid and on the grid there's going to be the grid component and beneath that there's going to be a tile map with the tile map and the tile map renderer we are going to rename that tile map for something like let's go and call this one floor and that is going to be our tile map that contains all the floor so fairly simple stuff we're going to go ahead and create a new sorting layer for it as well the sorting layer are actually shared with the sprites as well so as you can see if we click here you're going to see we have actor the sorting layer we've made in the pass for all the player object or the npc's object let's add a new sorting layer we'll call this one floor and we're going to make sure that this one is above actor so it is being rendered first so when an actor is on top of it this one is rendered last which means it's going to be on top so the highest one is going to be the one beneath everything the lowest one is gonna be the one render last so the one on top of everything with this new sorting layer we're going to click on our tile map so the floor tile map make sure we apply it here and we can then start adding stuff in our tile map but right now we don't have any palette so we have to go down here in the tile palette click on create a new one and that's going to be something i'll call dungeon we're only going to have one palette for this game but i've seen games in the past such as warcraft 3 they gave you editor you could swap in between palettes or like a winter scene a desert scene a forest scene that could be quite cool but in our case we only have a dungeon kind of settings so we're going to click dungeon make sure we hit create and it is going to ask us where to save it i'm going to go under artwork and level select the folder and you'll now see on the artwork level you'll see dungeon which is right now a prefab in this next step we're going to import what we've made in the past and we're going to put it in here now all they ask you to do is to drag a tile a sprite or a sprite texture here so if we go under atlas we have all our sprite beneath atlas so let's assume that we want to import our four crates i'm going to click on the first one hold shift and just drag and drop this in here and you'll see it gives some space for it and we're going to drop that there now it asks you for a place to save of course we're going to go under artwork level and i will be creating a new folder in here called tiles i'm going to select this folder and you'll see that it creates styles on its own right here so we can find our four crates and they can also have different color they can have different collider type so this is something really you can customize just a little bit right so let's have a look at what happened down here in our tile palette it gave us our four tiles but in a weird order so we're going to have to place them again so what i'll be doing is i click on the little edit button click on say this tool right here the select tool now with the tile selected i can now go on this tool the move selection tool or m and move it around just like this this one for selection is s so if we try to work quickly we can press on s select m move by drag and dropping so s select move and here we go we just replicated what was in our atlas and this way it can look good if we import all of these together we're going to be doing the same exact thing with the rest of the tiles so i'll head under atlas i'll take all the floors and i will drag and drop them right here making sure of course i save under tiles as you can tell there is going to be some work that need to be done and also for some reason since this is a very very early version of 2017.2 uh you can tell that my atlas just got messed up so hopefully in the version you're in right now that doesn't happen if it does you might want to import everything first before you you do any changes so i'll actually do that right now put everything else i need such as the healing fountain the pillars and we're also going to be using the stairs i'm currently holding ctrl to select what i need and finally the walls as well so this right here is going to be our tile palette and there's going to be some ordering to be done of course but i'm going to go ahead and save this one for now making sure it doesn't crash by hitting ctrl and s i went ahead and i closed the engine just to give thumb up a try see if my changes were saved after i just reordered a little bit of it and uh turns out that they weren't safe when i booted back up so um this is something i hope you have less problem than me on this but just bear with it if you are having the same trouble i'll be going through making the whole level manually using one tile at a time and when we need to do some special changes i think we're just gonna do them by hand but hopefully by the time you're watching this there is no bug in this and it actually save the state of your palette until then um just bear with me we're gonna have to deal with that so i'm actually going to end this episode right here in the next one we're going to lay down the whole main scene but the first scene the main scene is only going to be used just for moving around maybe interacting with an npc and really basic stuff also having healing fountains so some kind of safe place for the player to be so guys i will be catching you in the next lesson welcome back to another lesson guys today we are going to be creating the main level using the tile map editor if you have a look down here in my tail palette you're gonna see that it's a little bit different from the previous lesson that's only because i had to redo it i wanted to make sure i split every items in different section to make sure i have access to them because they were all clutter and it wasn't really useful since at the moment i'm not able to save my tile map or sorry my tile palette properly this is going to be the way i work on this project one big problem you're going to notice is when we try and click on something down here say the pillar we try to put it in the scene you're going to see we only have four spaces at the moment and that's because our grid spacing is not done properly so we're going to click on grid and make sure we change the cell size to 0.16 and that is because 100 pixel is equal to 1 in this case so if we want 16 pixel divide that so you get this amount right as you can tell right now if we drag our cursor around this makes a lot more sense and we can start spawning infinite pillars just like this okay the floor layer is really going to be used only for the background and also showing us where we can actually walk so when we go ahead and add additional layers such as a asset layer or a a wall layer collision layer you're going to have better ideas where to put it because we're going to have the floor layer so we're going to start by actually making sure the camera is on as you can see we have the main camera make sure the camera is expanded so you can have a nice view of where it actually hangs in your screen now remember that that camera moves so you're going to have to give yourself a little bit more room on the outside so this way you don't see some blue pixel that is the color the camera is rendering in the background where it needs to clear alright so we have this selected we have the black square selected right here and then you're going to click on this tool up here or you can press u on the keyboard and you'll be able to drag and drop big areas like this so what i'll do is i'll just say take five in diagonal here so one two three four five drag and do the exact same thing on this end so one two three four five and then i release the drag and that's going to be the background the black background behind everything now to show where i'll be walking around i'll just take this color right here that's part of the floor that is the floor underscore zero asset and we're going to just give ourselves some room for the player to experiment when he first joins the game so maybe oh let's use the other tool maybe that much room so he can just walk around and you know feel the controls a little bit and then when he needs to leave and actually go like in adventure or something for combat and more we can give him this kind of pathway to go up and up here is going to be some kind of portal he can join so that's going to be really the layout i'll be using and if we just play this real quick let's have a look if we can actually see beyond this so i don't think we can see beyond this unless you actually go through the wall in this case but just to be sure we're going to give ourselves one more square of space and here we definitely can see at the top bottom seems fine so bottom is fine but for the other one we need to put some more squares now we have the old another old but we have the the light color right here and we want to have the dark color to fill those in what we can do is hold alt on the keyboard actually it is going to be holding control so you're going to hold ctrl on the keyboard and click on the darker one this is going to be a color picker and you'll see you can now use this one so i'll be adding two square on the left and two square on the right and maybe something like four square at the top so maybe even five it really doesn't matter how much you put just make sure you can't see beyond that point if you stay of course on your floor layer which in this case everything works fine now the second layer we're going to put is going to be some kind of accessories layer um it is not going to be where we do the collision but it's going to be where we put some walls in graphic and you know we're just going to have a good time doing that so let's make sure we right click on grid and add a new tile so under 2d object add a tile map this one is of course going to be the wall or we can just call this um accessories or design because this is going to be just graphics really so this is going to be some kind of asset there's going to be the ealing fountain there's going to be the walls but it's not going to be the collision layer you'll know what i'm talking about in a moment okay so we're going to make sure that this one is above by actually putting it on the floor layer let's put both on floor layer actually and this floor layer is on order and layer zero this design layer should be on the one so one above that okay next step we are going to start designing this so fairly simple stuff i think i'll be using some of these wall and i'll just put them right about there and as you can tell if we do that we override the last one so we're currently not on the good layer we want to be on the design layer right now we're on the floor to change this what you have to do is go in the tile palette and click on the active tile map put that on design and now as you can tell it's going to keep the background right there so i'm going to go ahead and um just do a little bit of design i'll put that here it's really subtle but they have one pixel say on the left here that's closing on the left and they also have others that have the closing on the right like this one very very subtle this one has no closing so that's the one you put in the middle and you just keep on going like this so same thing for these i think you can actually stack them so if you want to have two two floors of that you can do that in my case i'll just be keeping it simple with a single floor and if you want to work faster what you can do is of course use that control key so in case you want to do another layer up here we can do that something like this is going to work wonders right so um let's keep going that direction i'll be removing this one in the middle now if you want to remove you're going to have to hold shift and drag where you want it to be removed so just like that i remove those two i'm going to replace them by stairs so i'm going to go ahead and start laying that down um say right about here and we now have stairs that go there i'd also like to have e-link found then next to the door just in case the player wants to exit really quickly and heal himself so i'll put some right here let's make sure we put the head as well and now he's going to have some healing fountain we also have the pillars we can play around so maybe put one here i'm going to replace what i had and maybe even do something like this of course it's all a matter of experimenting and finding what looks good for you i'm going to keep on going by putting some floor design right here just changing the aspect of the floor that floor by itself is kind of boring so we're going to go and make it quite big make sure we have different shapes in it so i'll go like this and then take the top part duplicate it few times and just keep going in that direction until we have something that looks good so i went on and i added an additional floor right here um at the top and i've also added a lot of these little wall just to give the player the impression that he's high somewhere on top of a castle or something and i like also to put some crates just to put some additional stuff why not we have crates why not put some and here we go so we have a couple of things now now i'm also going to go back on the floor layer just for a little bit and just give it an additional touch right here so you have the feeling that you have to go back up there um let's give this a try in the game see how it looks so you can go left you can go right when you go up this is what you see so that's going to be it i guess for the um those two layers we can add more details of course later on we just want to have a basic level completed now the really important part is the next one we have to create the collision layer so what i'm going to do is i'm going to right click create a new layer just like we've been doing a new tile map this one's going to be collision and i'm just going to make sure it's on top of everything right now so i'll put that on floor put that on say 5 and we're going to go ahead and draw the collision so changing the active tile map to collision taking whatever color you want like that black color and we're going to be putting that where we don't want the player to go so here is fine he can go uh behind the crates but on top of the crate i don't want him to do that uh we don't of course want him to go right here that's illegal that's also illegal make sure now i know this is a bad color black is also a very bad color for what we're doing since it's also the same color as the background um so we're going to have to do that and remember where it is maybe if we can focus on the title map oh yeah right here that's good so change the tile map down here put that on focus on tile map and you're going to draw it all around where the player is not allowed to go so really see that as if it's black the player is not allowed to walk on it so i'm gonna put this right here he'll be able to walk down there that's fine and on top of this fountain we don't want him to be walking directly on the wall but he can walk in the little pool down there that's gonna heal him in the future also lock this up here up here and something like this so that's going to be the collision mesh for this game actually for the scene and um what i feel like doing is just turning off the tile map renderer so you don't see it but it's still there and to give it a collision you're going to change the layer at the top remember we made a layer for this it's called blocking so you're going to change that to blocking and also add the tile map collider 2d which is going to give you this in the end and you can just turn off the tile map renderer and you'll see that it's still there and if you play the game even though you don't see it you're not allowed to collide with that anywhere you go you're not allowed to collide with that as you can tell we can go behind the crates we just can't go on top of it so that's something um pretty cool but we'll have to fix the rendering order so that one is on top okay so the rest seems pretty fair maybe you want to lock it here we don't want him to go down there and then at the top here is going to be our portal to go to the rooms or to the dungeons all right so that will conclude our lesson today guys thank you so much for watching in the next one we'll be creating a dungeon welcome back to another lesson in this one we will be creating a new dungeon that will be added next to our main scene so you'll be able to go from the main scene to that dungeon later on in the course but let's go ahead and get started i've just created myself a new scene so i went up here click on new scene or ctrl n i'm going to save this under the name dungeon 1. you are free to do as much dungeon as you want okay now you probably notice i have ordered my palette over here on the bottom left and i am now ready to start editing this thing so i gotta make sure that my main camera is on size 1 for the orthographic and then i will right click create a new 2d object tile map go in my grid and make sure the cell size is 0.16 and we now have the same exact setup as we had inside of the main scene now what i will be doing is renaming this one for floor and i'll be creating a very a very simple dungeon it's going to be something quite small i'll start by just grabbing all of this go here paste that somewhere where the user is going to spawn at the very beginning i'll maybe give it one more row and then we'll just extend that towards this side and then maybe go off like this create another big square oh my bad and then maybe go up i'm just randomly making this pattern right now um i'm not quite sure exactly how yours is going to turn down of course i recommend that you use all your creativity to make some awesome level but i'm just trying to go fast like i said it's a very very small dungeon um but you know it is going to have all we need for this thing the boss room is going to be quite big and squarish and here we go so i've got pretty much all i need now i'm going to start decorating this thing maybe by uh changing the floor a little bit so i'll make sure to take the floor add a little bit of pattern just like i've done where the player starts could have one here i could technically add one in the bus room as well and these are kind of dialable so you could go ahead and just like go on like this and keep on making this and changing until you cover a bigger area just like i am doing right now so it's really up to you you have some thoughts you can work with which is quite cool and uh which is also why we love this little tile set and here we go okay right so this is going to be the boss room now what i'm going to do is create another layer i'll just duplicate floor for now actually i won't duplicate floor if i duplicate floor i'm going to get this as a copy we don't want that so i'll right click create a new 2d object in your tile map the purpose of this style map is for me to actually keep on working on the floor keep on making the floor adding walls next to it adding some visual visual stuff around the floor but um there are some places where it overlaps so let me put that on active tile map other and then i will go ahead and just use these at the top here and i am going to put them right on top something like this now like i mentioned i want to be able to overlap like over here this is overlapping the floor if we were on the floor layer this would actually disappear something like this so we don't want that this is why we created a new layer now also uh let's make sure our other is higher in priority so i'll put order in layer one and let's keep on creating this we can we can copy a a tile that is already in place by holding control and the rest is just your usual tile map stuff so i'm going to go ahead quickly fill this in i don't want to be taking too much time because this is not you know this is not your creative thing um we're here to code we're here to learn how to make the game don't want to spend too much time making the level but just know that level design is a whole other thing it's a whole other art that you'll have to master if you want to make some very very good game unfortunately this is not a course about it i wish it was but it's a lot longer uh to explain and a lot of more feeling based off which i don't have so much as a programmer at the moment okay final one we are then going to be able to start spawning the wall around this oops mistake here we could go ahead and start spawning these beneath but you know what i will be doing that last i'll start by just adding as much of as i can and i'll reserve that long and annoying part um for the very end all right now over here we could also be putting a font and i was thinking about putting it here but that's not really making any sense with the amount of tile we have so let's go ahead and expand that to one more on this side and also one more on this side here all right i'll go back on the other just fix this little mess good thing we have the ctrl key and the shift key to remove and i'll also go back on floor and do something of the sort over here okay now we should have everything we need um to lay down a fountain so i'll be doing that over here oh i'm still on the floor let's go back let's do that on the other now we can go let's put that on the floor that's fine and i might need another wall and here we go so we have fountain this is where the player is actually gonna go heal himself before he go fights the boss so i'm going to go ahead and just fill in the rest of this thing going to fill in um the rest with these wall over here and i'll just make sure to put a bunch of them pretty much everywhere okay so i'm pretty much done adding all of these wall as you can see here uh one thing here is that i cannot keep on adding walls at places like here simply because it's going to go over this layer so the best way to fix this would be to actually create a new ui tile map and just sneak that in in between so i'll go here tile map and i'll just call that floor dash other i'll put that order one and i'll make sure other is on two and it's going to be something i just put in between as you can see it should take me oh i'm not on the road done the right time up here on the active tile map i'll go on floor other and if you can see here i will sneak this in right in between now um i'm not sure if this actually looks good i don't think it looks good so i'll be getting rid of this here and that one there and i'll just replace this other thing here by a little bit of shadow and here we go so that's going to be first level now in terms of what's going to be inside of it like the um the gameplay prefab we're going to put inside of it so the chess the enemies we're gonna be doing that in the future right now we have something we can just play around with and uh you know that's that's all so i hope you understood a little bit of how to use the style map the feature is a little bit bug if you're using this in 2017.2 you might run into some bugs i'm not going to lie i had a bit of a problem uh making this style palette stays the way it is right now actually i was not able to do it just yet since the progress was being raised every time which is quite annoying but if you do run this a little bit later hopefully the bug is fixed but until then we are going to do what we can with what we have but there is one thing left we are going to right click on grid to the object and make sure we have a collision layer let's put that layer on blocking make sure we have a tile collider 2d and let's draw right on top of it so i'm going to take the black square and start drawing make sure your active tile map is on collision and you're going to go ahead and just start drawing the collision over here you can see it pops as green or you can just put the ordering layer to say something like five something that is above everything so you can see and i'll just go around and do this should be fairly fairly easy to do we only have a small level thus far and make sure you don't forget the pillars over here so i'll go ahead and do a little dot for those pillars if you do a mistake hold shift there you go and that would be our collision for this whole level fairly simple once you're completed go ahead and turn off the tile map renderer but the collision are still going to be there all right now that should be complete for the section three i do encourage you to make your own level make a bigger level this one is quite simple and it's going to be only used to uh test out the mechanic will implement in the game but of course i don't create so much content on the scores you are encouraged to do that on your end though okay so that concludes the section three i will see you in section four welcome back everybody we are in section number four and in this section we are going to create some collidable object something you can interact with as the main player so we are going to start very very simply by creating a a script called collidable and collidable is going to be a script that we will be putting on every single object that you can collide with whether it is something that's going to be destructible or even a npc you talk to or a chess that you loot all of that is going to be under a single script and that is what we'll be doing right now actually we are going to turn our test npc into a collidable object so let's go ahead right click on script and create a new c sharp script i'll call this one collidable we are then going to open it up in your favorite editor once it is open as we always do at the top of your script you're going to declare some variable things that we're going to need as the collidable object so what is it from outside do we need to make this script work well first we're going to take an object called contact filter 2d and that's going to be some kind of filter to know what exactly you should collide with we'll see more about this in a second and then we'll need a box collider 2d which should also be on this object so we made it private the reason i made it private is since it is on the object we don't need to drag and drop this for every object we're simply going to assign the box collider in a start or a way call and finally we need a private collider 2d array called hits and you'll see why we need this once we lay down the formula but basically this is an array that is going to contain data of what exactly did you hit during this frame and i put a maximum of 10 in here 10 is a big number actually we don't need that much because every single frame you could be in collision with say maximum 10 different thing in this case um technically you're going to be in collision with more but with the information we're going to receive we're going to limit that to 10 and like i mentioned 10 is already a big amount alright so i'm going to go down here and write down a start but i'll make it protected and virtual and we'll see what this means in a second if you've done inheritance before you'll understand and if you haven't i will go briefly on what inheritance is as we do it so in the start just imagine this is a normal start if you don't know so in the normal start we're going to do a get component type of box glider 2d which means that whatever object the collidable script is on it requires a collider 2d what you could do in unity they let you do that at the top of your class you can say require component type of box collider 2d and this is going to automatically add a collider 2d to your object let's give this a try just to see what happens so right now we don't have any collidable script let's put it say on the main camera i'm going to drag and drop this on the main camera and as you can see it created a box collider for us now we don't need that on the camera so i'm going to remove it you have to remove the collidable script because of course it depends on the boss collider but as you can see this is what the require component does in my case like i mentioned before i'd rather not have this here i'd rather have an error instead that's going to let me know that boss collider is not defined the reason i would rather have an error is quite simple when they put the collider to the inner object you don't define the scale they put one automatically there so i'd rather be told that there is an error and the collider is not you know is not put properly then have it put there automatically and not the way i want it second function is going to be a update so private virtual void again and we're going to be creating a normal update like if you haven't done inevitance like i said normal update this is going to be for all the collision work and this is what we're going to be doing so we're going to take our box collider 2d and we're going to cast the function overlap collider overlap collider takes in our contact filter this is why we need it and it also takes in an area of result where to put it which is also why we declare that at the top so these two go hand in hand together alright so once we call this function what this is going to do is take your box collider and actually look for other collider beneath it or above it so something in collision with your box collider right now and it's going to put it inside of the hits array so let's actually iterate over this array we're going to do a 4 and what i do here is i type in 4 and i double tap on tab and it is going to auto complete this for me so for and i is equal to 0 as long as i is smaller than hits dot length so we're iterating through the whole array we're going to check if hits at the index i is equal equal to null that means there's nothing and that's going to happen every time because you know the array is a size of 10 and you might not hit 10 things at every time so you have to make sure that uh you check if it's no or not if it is null we're going to continue now if this is not null we are going to do a debug.log and just shout out what is the name of where we've hit so let's do hits at the index i dot name this way we can know what we collided with and then um the arrow is actually not cleaned up every time so we're going to clean it ourselves by doing a hits at index i is equal to null so let's give this a try we're going to put the collidable on our npc so where is rnbc right here i'm going to have the collidable script on it and it's not going to create a box collider because first we remove the required component and second there's already one on there so if i press on play now every single frame you're going to see what this player the test npc is actually entering collision with so as you can tell right now the testing pc is in the ring collision with player zero which is my my main guy and this is what we need so we need information on what is actually hitting us right now and this is going to help us in the future like uh instead of having a debug.log in here we could say something like uh send text to the player tell him what to do or give him hp or sell him hide them all that kind of stuff could be done from right here which is also why we're going to turn this thing into something more general because if it is a npc maybe he wants to say something to the player if it is a chess maybe he wants to reward the player with some pesos or something so we have to make sure that we can actually work with this function in any cases now we could go ahead and say well if this dot tag say it's the npc number zero then you're going to say something if it is a pesos chess then you could go ahead and grant pesos but that is just too much work that is not something really efficient we are going to do something else instead we're going to be using the power of inheritance and to do this we are actually going to create another function this one again protected virtual void on collide and we'll send in a collider 2d that i'll just call call and here is what's going to happen here debug.log call.name the exact same thing and we're going to make sure that in between where our debug.plug was in the past we're going to say uncollide with hits at the index i because of course hits at the index i is a collider 2d so what we've done here in this very specific case is nothing it is the exact same thing as it was a second ago we just changed the flow of things so this way once you enter here and you call the uncollide instead of just doing the debug.plug it is going to go to this virtual function and do it here instead now through the power of inheritance we are going to be able to change the content of this function through different means so if we are a chess we're going to be changing it to something like grand pizzas if we are npc uh change it for something like talk to the player that kind of stuff is doable if we use inheritance and that's exactly what we'll be talking about in the next lesson in the previous lesson we learned how to make something collidable using box collider 2d and our little script over here but we didn't really make it so it could change right now we only have one function that does a debug.log and that's all it does at the moment what we're going to do in this lesson is we are going to create a chess that is going to use the collidable function to give the player some pesos okay so in order to do this we're going to start by needing some chess so i'm going to open up the atlas once again go under the sprite editor and just crop some chess really really quickly um i'll use two of them so this one over here that's open and empty that's going to be chess this is actually going to be chess 1 make sure it's 16 by 16 and this one just be needed is gonna be chest zero here we go let's hit apply we now have these two new sprites in our collection i'm going to go ahead and find the chest 0 and drag it somewhere in the scene so it is right here behind my actual game i'm going to have to go under the sprite renderer and give it a layer so i'm going to add a sorting wall this is going to be interactable and let's make sure my chest is in that sorting layer we'll now be able to see it over here i'll reduce the size to something like 0.75 on both axis and we now have this thing all right now the question is how do we use this collidable script and turn it into something useful for the chess well first up let's make sure that this chess has a box collider 2d as you can tell they mention it down here there is no box collider 2d attached to the chest 0 object so we're gonna actually give it one and as you can tell we now have a collider 2d now our very next step is going to turn this what you see over here in the console so the player zero called into the grand pezo call to do this what we're going to be using is called inheritance and it is a concept in programming that is pretty much everywhere in high level languages such as c sharp and even c plus plus what we're going to do is actually get rid of the collidable script so remove component now we're going to head over to the script folder create a new c sharp script call it chess and we're going to open that one up now at the very top here you might be wondering what is this over here the mono behavior that we see all the time well model behavior is something that we inherit from meaning that your chest even though it looks like there is nothing in the class right now we still have access to a couple of thing as you can tell first off we have the you know the private void update we can use we have the private void start and anywhere you are in that object you still have access to things such as transform collider even rigid body i think this one is yeah this one is deprecated but as you can tell we still have access to all those things including get component now these are not something native in c sharp those are not something native in in the code in the language we're using it is something that unity gives us through mono behavior and now let me tell you a little bit of a secret if you double click on metal behavior and you press f12 you'll be able to see what's inside of it so every time you actually create a class that inherits from mono behavior you also inherit from cancel invoke invoke stop co-routine start co-routine all that kind of stuff but you also inherit from behavior because model behavior inherits from behavior so you also get this one what's inside of it enabled is active and enabled you have function you can call on your object but you also inherit from component this one of course has all these things we just mentioned so so every single object you create under model behavior have all these things and that's a that's a bunch of thing you can call so they also had from object and object is the final one but you're going to see function we use such as destroy don't destroy on load instantiate all that kind of stuff and also some override over here so we we have all of that in chess at the moment it doesn't look like it but chess has all of these and that is because he he merits from monobehaviour now what we're going to do here is we're going to add a layer on top of that you saw how we have mono behavior and beneath that there is a behavior then component then object well we're going to add our own layer we're going to add collidable right so how does that work chestnut inherits from collidable and collidable inerras from monobehaviour so we still have the same exact thing as we had in the past but we include all of this on top let me give you exactly an example of what this does if we go back on our chess as you can tell there is nothing on there there is no collidable we're going to add our very new script which is you know it's pretty much empty as you can tell it's just this but it inherits from collidable what happens if we actually go on top same exact thing as if we had the collidable so you can think of it as some kind of copy paste of what we had in collidable and we just put it inside of chess there is some neat thing very nice things you can do with this and it is the fact that you can change some function that collidable has because we made them virtual virtual means they are defined they are there but you have the opportunity to change them you have the opportunity to override them and this is exactly what we're going to do right now so we're trying to change this bit of code for something like grant bezos right so what we're going to do is head over to the chess and type in the exact same security type so right here was protected we're going to say protected and instead of doing virtual we will do a override as you can tell they are actually recommending it to me so we can override start we can overwrite update and we can also write on collide right here we will want on collide so let's make sure we include that one now they're going to give you something called base on collide which means you'll be able to call the one from your parent you'll be able to call the one from collidable if we leave this in there same thing happens you're going to see that it still calls the name of the player player 0. now if we go back and remove this just leave this as the empty function it is still going to call the function however there is nothing in it so we totally destroyed the one in collidable we didn't really destroy it but we are not running the one in collidable anymore we're running the one in chess and the one in chess is empty we could call the one from collidable if we decide to call it using base just like you saw over here now we do not want that here we want to give the player some pezos and unfortunately we haven't created the code around that so we'll just say grant bezos let's have a look what this does in the game and here you go so we totally change this what we receive over here before so the name of the player to this grand pezos these two things they both use the code behind collidable.cs but they have different behavior and this is the power of inheritance and there is a lot more thing you can do with inheritance but this is the main big thing that you'll want to do with it so we'll be using it quite a lot and if you did not really understand this concept i really recommend that you go watch the video in the resources there's another additional video you can watch it's on my youtube channel right now but it is something that might help you understand a little bit better it is something you'll want to use in video game in any video games you're making this is something that is really really useful alright guys i will catch you in the next lesson in this lesson we're going to keep working on our chest but we're also going to create a additional layer in between collidable and chess because there is other thing we might also want to collect in the future so we are going to create a class that is called collectable in between collidable and chess and the reason i'm doing this is because if we have a weapon and that weapon you can swing it around in front of you you don't want this to be collectible but you want this to be collidable so we're going to create this additional layer and also if you want to have something else than just chess that you can collect in your game you will be able to inherit from collectible and not collidable let's add a little bit of logic in here we are going to go right in between these two by making sure this one inherits from collidable and now we're going to go in chess and make it inherit from collectible everything is still going to work because just imagine we just did a normal copy paste but this one has nothing in it so it has nothing to bring to the table just yet um we are going to create some logic field at the top though so the logic field we're going to be using is a simple protected boolean called collected and that is the only thing we're going to need so now imagine that this is a normal boolean so a normal variable just like we've been using thus far uh it could have been public it could have been private but in this case it is going to be protected just like the function we saw in collidable those are protected protected basically mean that it is private but your children are going to have access to it so it's going to be private to everybody but your children in this case chest is a children of collectible and collectible is a children of collidable so this one they have access to the protected function and also the protected fields or protected variable from their parents in this case if we create a protected bull nobody's gonna have access to it but itself so collectible and also chess as you can tell from chess we can say collected and that is our boolean if it was private we would not be able to do that if it was a private bullet just like this you don't have access to it it doesn't even show up so this is what protected means and of course if it was public everybody even even your player script would have access to it so this is something you might not want in this case we don't need anybody to know about our collecting or collected status if it's not us we're going to keep this here and we are now going to override a function so protected override void on collide now what we're going to do in this case is a simple check that simple check is going to be is it the player that's actually hitting me so if call dot name if the the name of the collider is player with a capital p then we're going to call a function called uncollect just like this uncollect is going to be a function just like oncoly so it's something we're going to override is something that we have to declare down here and we are going to do that right now so private void on collect the reason we're not going to need anything in parameter is because we know that it is a player the reason we know is the player only the player or any collider with the name player is going to be able to call this function so collected is going to be equal to true that's going to be my simple logic right here now why exactly did i do that why did i not just leave it the way it was well it is quite simple if we actually um put that on collidable like it was before you're going to see that if we move our chests anywhere else where there is a collider say right here this is a wall collider it is going to grant pesos even though the player is not on top of it and that is not something we want so definitely we have to check whether this is a player hitting you or not and we could have done it like there is nothing stopping us from doing it here so if call dot name is equal equal to player then of course we could have done it that way by the way since we're using collider.name we have to make sure the collider the name of our player is really player really really important let's change the name of our player to a proper name okay so just to make everything clear we are now in everything from collectible but we could have made the call right here like i said if called that name uh is equal equal to player instead what we're going to do is totally get rid of all of that and to grant peso this time we are going to override so actually let's make that protected override and we're going to override on collect and when we do uncollect i'm going to leave the base in here and i'm going to say debug.blog grant bezos now if you're curious why i decide to leave the on collect the base on collecting here it is simply so we can have this call collected is equal to true remember that on collect the base function has this as you can tell selected is not equal to true now if you do not want to have the base on collecting here if you think it doesn't look good if it's not clean in your code if you can't read it properly because of course um every time you want to know what is inside of on collect you're gonna have to go back and check okay so collected is equal to true that is exactly what's going on right here just copy paste what's in there now um of course if you don't want to have that you can simply type it right here so uncollected is equal to true now let's go ahead and expand on the logic of this chest so this chest is going to have to do more than just a debug.log we are going to start by if statement so let's just disregard all of this we're going to start with the if statement if we are not collected so if collected is equal to false and false is shown here by this exclamation sign well if it has not been collected let's say that it has now so collected is going to be equal to true and then we can do our chest logic now we don't really have anything to track the amount of bezels our player has so we're going to go ahead and work around only the visual aspect of the logic thus far so what we'll do instead is we're going to work on the visual aspect of it so we're going to say public sprite empty chess sprite and also public int pesos amount the first variable right here the empty chest is going to be so we can swap the full chess sprite to the empty chest once we collect it and then the pesos amount is going to be to say how much bezos are you going to earn from that now i remember in the design the little design i've made one point of reward was equal to five pesos so i'll make sure i put five in here but you can change it directly on the chest if you want to since this is a public end okay let's keep on writing this logic so what we have to do here is we have to grab the sprite renderer of our object and change the sprite on it we can do that with a get component so let's do a get component sprite renderer and change the sprite it's going to be equal to empty chess okay um next up let's do a debug.log again so we know that you know it happened debug.log and we're going to grant the amount of pesos through tax right now so grant plus pesos amount plus bezos a little exclamation sign just to show how happy we are we gain pezos and let's give this a try now so nothing happens we go here and i just realized we're gonna have an error um we did grant five pesos and the chest totally disappeared the chest disappeared because it changed the sprite to none i thought we were going to get an error we didn't get one apparently it's fine to have it on none but we're not going to leave it that way let's make sure we go back on the chest and here where it says empty chest you're going to find chest one and just like this we're gonna run this again and the chest is now empty once we walk on top of it plus we have been granted five pesos if we want more scroll this go ahead and play the game and we're now granted eight five five pesos which is too much okay let's put it back on five make sure we change the name of chess to chess and we're going to put it in our prefab so now we can spawn chess wherever we want by simply drag and dropping this in the scene here you go so we got a couple of chests around now and this one here could grant 10 pesos this one could grant 25 and we can now play this this one gives 10 this one gives 5 25 and so on guys so we're actually going to end this lesson right now and i will move on to another collidable object in the next one cheers welcome back guys in this lesson we are going to make another collidable object this one is fairly a simple object but is something we will need for the game flow of our game so it is a portal object something that is going to teleport us to another scene now i don't think i'm going to have a sprite for this one i think i'll just leave it blank and the player is going to have to find it so at the top over here i am going to create a 2d object this one's going to be a sprite i'll put a box collider on it box ladder 2d of course make sure i open up my box slider and now let's actually play with these i will be editing the collider so i can actually grab the sides and just make a zone in which the player is going to step in and trigger the on collide thing so right about here sounds fine you can make it bigger it doesn't really matter at this point because you know it can't escape from the two other sides right so this is going to be my portal it doesn't look like much you can't even see it but we have the zone and this is all that matters to us so let's change the name of this to portal and now we are going to create a new component i'm going to call this portal so again create a new script put it on here apply to portal and then we're going to open it up and we'll redo the flow one more time so you can understand exactly how to override a function just like we've done for the chess this is going to inherit from collidable and make sure it's not the collectible we're not trying to collect the portal we want to collide with it and to override the function we use the same exact security type so in this case protected override on collide let's check this is a player so if call dot name is equal to player then we're going to teleport him so teleport the player okay so where exactly do we want to teleport the player we're going to give it a random dungeon so we don't really know which dungeon he's going to get it is something that's going to be random now the way we're going to do this is by creating some kind of logic right here i'll do a public string array and that string array is going to be scene names so there is multiple strings and it's all going to be the scene names then once we do collide we have to pick a random scene in there and just load it so we're going to pick a random one doing string scene name so this one is singular is going to equal to c names the array and we'll do a random dot range 0 cnames.length just like this what exactly does this line do this line creates a new string by itself so it's not multiple string it's not like this one here this is an arrow string so you can have multiple one um this one is singular a single scene and we're going to pick a random scene in between 0 and the amount of scenes inside of the scene array so we just get a random scene in there and then we're of course going to load it up to load it up um there is multiple way you can do that so when you load a scene in unity what you can do is use the scene manager and do a load scene exactly written this way now to have this working you absolutely need to do using statement at the top now this is something you're going to see at a lot of different places people on the web they like to do that i personally like to do something else instead of having a using statement at the top i will just put it all in one single call like this so unity engine scene management scene manager load scene and i'm going to get rid of this one at the top and also why not get rid of the other one as well if i only have one load scene i'd rather just call it manually like that and that's it that's all we need to do for this script so let's give this a try we have we currently have only two scene at the moment we have main and dungeon 1. now obviously we don't want to load the main scene again but for testing purpose we will actually put it in the array so on the portal object find your polo script and you're going to have a size say two first one is going to be dungeon one and second one is going to be main so there's gonna be one out of two chance to reload the same exact scene and there's gonna be one out of two chance to loan the dungeon one now you're going to realize as soon as you step in there you're gonna have a error and that is simply because we have not added them to the build setting this is something a little bit complicated to understand when you first start off using unity but all of these scenes you create are never put in the real game until you add them to your build settings and this is really useful for multiple reason while you're developing your game you might have some something we call gym scenes so hidden map developer maps that the real player is never going to see and you've been using those map to test out say the distance in between your jump you test out different gameplay prefab or just you know just to mess around and try to create something try to create the new level this is not something that would be completed and it's not something you want to ship in the final game so technically you don't add it to the build settings however these two scenes we want to add them to build settings we want them to be included so we'll go up here under file build settings and the scene in build are currently empty we'll make sure to drag and drop main and also dungeon 1. make sure main is the first one then we can play the game go here and as you can tell we've been teleported to the other scene to dungeon one and uh dungeon one has a little bit of issues with the camera as we as we could tell a second ago so i'm going to fix that put that back on 1 and here we go let's go back in main give this a try we're going to collect the first chess go here as you can tell we've been re-teleported into main which means that we hit the one out of two chance of main being reloaded now let's go back this time we loaded dungeon so that's pretty cool we have our portal working and we did another example of inheritance so quite happy about that this will conclude the interactable section and we'll then move on to the next one in the next one we'll be doing a lot of saving stuff so we're going to be saving our state in between the two scenes so this one we're in right now and say the dungeon so we can keep the same amount of pesos in our bag we can keep the same gear we can keep the same experience amount we're going to be working on all these nice stuff just to connect everything together in the next section so guys thank you so much for watching and i will see you there welcome back to a new lesson in this lesson we are going to create all those little feel all those little variable that we should have been keeping track of since the get-go we're talking about the amount of pesos the amount of experience our character has his weapon and all that kind of good stuff so most of them are not created just yet so we're going to lay down the groundwork and once we're ready actually implement those so let's go ahead and open up our script folder i'm going to create a game manager now this one is going to turn into a little gear by default because unt just likes to do that it recognizes game manager as a script that is going to control a lot of things but just tell yourself that nothing change is just like a normal c sharp script the first thing i'll be writing in this game manager is a public static instance of myself now if you don't know about static it is something you can access from everywhere in your code so assuming that we are in portal right now we can access instance which is our field over here we can access that variable by doing a okay manager getting the type of my object so that's the name of the class just like portal and then dot instance and it is going to be there because it is static now what that means is that we could get the instance of a game manager from anywhere now the question behind this is which instance is it going to be because in case we have two game manager which one is it going to pick well we have to make sure that we only have one that's the big problem here and we're going to make sure that the instance is going to be equal to this so once we start the game we're going to assign this to ourselves which means if we go here we say okay manager.instance this is going to be equal to the instance we're going to put in the scene so it's going to be equal to something at least it's not going to be null it is going to be equal to the first game manager that it finds in the scene which means we have to put that somewhere so under main i am going to right click in here create a empty game object it doesn't need to have any mesh doesn't need to have any sprite this is going to be our game manager i'm going to put a position on 0 0 0 and add our new component to it right so now we only have one game manager and this one is gonna be the one equal to instance okay so now we have this one script that is going to be available anywhere in your code this one script is going to contain a couple of things first off resources for the game i'll be typing in for field in here we won't be using them all today but we're going to be creating a list of sprite and that is going to be the player sprites right now we only have two public list of sprite and that's going to be the weapon sprites then the public list of int this one is going to be the weapon prizes when we upgrade public list of int again and this one's going to be the xp table so how much xp do you need to move on to the next level these one we're not going to use it just yet but at least they're going to be there and then we'll need some more logic stuff so actually not logic we're going to call that references references to different things such as the player script the weapon script so public player this one we already have so we can leave it in here there and there's gonna be something like public weapon weapon and so on depending on how many references we need for our game okay next up we're gonna need um something to keep track of the amount of pesos so just some simple end i'll just call that logic in here and it is a public in 40 pesos so amount of money you have right now public in experience how much experience does your guy have right now all right so this is going to be enough for right now we have a couple of variable right now we're not really using them we know this one exists we can have a reference to our player we'll do that manually in a second uh these one they're brand new we're going to be using them in the save state and this one are just here for uh for the future so they're going to be resources for the future we are going to be adding a couple in here in between here in the future but right now like i said that is going to be enough and we're going to move on to the function we're going to start with one called public void save state this one is going to save your game then public void load state as expected this one is going to load up your progress those two are pretty much focused around the same state of your game so let's actually just say that at the top here save state okay now um sometime i do export these functions somewhere else maybe i put them in a other script and i also put the pezos the experience all everything i need to save could be in a different script and i just decided to serialize that as a whole but right now we're not going to need so much we're going to need the um the skin that the player prefers we're going to need the amount of pesos you have we're going to need the experience and also the weapon level um all these things we can actually get from the game manager itself all right so before we actually go and write these two functions how we're going to be saving this let's actually just hook them up at the proper place so we're going to write debug.log save state for this one and this one's going to be of course load state and we have to make sure that we load and save at the proper time when looking at our game we need to first load when the game starts of course we need to make sure that we have the proper data as soon as the game starts and then we need to save um we could save at any time we get something so as soon as you get a new chest a new amount of pesos you could call the save state that could work or you could save every time you change scene at this point i think it's really up to you you could save on your button click but just to keep this fairly simple i think we're going to save every time we change scene because it's only a function call in the end all you have to do is call that one function and it is going to do the whole saving process okay now how do we save actually how do we load upon starting a scene well we do have some callback that unity gives us so we can actually call a function when the scene is completely loaded we will be learning about these function in the next lesson welcome back guys welcome to another lesson in this one we're finally going to tackle the content of same state and a load state these ones are going to be quite fun to do quite simple as well and um we're going to do exactly what we said in the theory video so all right so the first thing i'll be doing at the top here is give myself some space to type in what we need to input in the save state so first off the first value we'll need is a int called preferred skin this is the skin your player is going to like like the most in the character selection so which character is he playing right now the second end could be the amount of pesos he has the third in could be the experiences he has and finally one more for the weapon level and i just realized that i'm not constant in my writing so let's fix that there we go and that's all we really need when you think about it that's all we're using that's all we need to conserve in between the scenes so let's actually code this fairly fairly simple stuff we're going to start by declaring a string s make it equal to nothing i called it s for saving and by the end of whatever we do in between here we're going to have a player pref so let's fix that player pref save actually it's going to be set string and that is going to be our save data so we need a key and then a value the key is going to be save state and the value is going to be s now we have to fill that s with our value with our data so to do this we're going to start by saying s plus equal which means we're going to append to this right now there's nothing in the string so we're going to just set it at the beginning and what we're going to do here is get the current skin because the very first thing here is the preferred skin unfortunately we don't have that just yet so we're gonna set something say uh we're gonna say zero for now and then in between every single number we is going to be a pipe sign pipe sign for me is alt code 124 so i just hold my left alt button and do 124 if you don't have it on your keyboard like i do second up we have the amount of pesos this one we do have so let's say pesos to string making sure our end turns into a string and then plus alt 124 and next up we have the experience we also have that so experience two string plus the pipe sign once more really important you don't put the pipe sign in between single calculates actually you could but you have to make sure um that this is actually set on two string because if you do something like this you're going to end up with some weird bug you have no clue what happens what happens is it actually takes um the int value of experience and it adds the end value of this pipe sign and it gives you just a weird number uh that you don't really want so really make sure this is a string and this is a two string just to be a hundred percent sure you don't end up with some weird bug and finally we have the weapon level again we don't have the weapon level just just say plus and here i'm not going to do a a plus pipe sign like this because we are not going to need it that is the final one that is the final value in our save state if we were to expand on this then sure i would put that and then create another line and that's what we need actually that's everything we need for the save state now when it comes down to loading the state is going to be a little bit different but very very similar in some way we're going to declare an array of string called data and that array is going to be something we load so player pref and instead of doing a set string we are going to do a get string the value of the key save state make sure it is the same exact thing you type here and here we go now this is going to return you a string but what we want right here is an array of strings so multiple string this is why we're going to add dot split and we're going to split on the pipe sign now you have to make sure it is single quotes because this is a character and it's not going to be interpreted as the end right all right so what this is going to do is assume we have something like this in the memory in the player prep assume we have zero um say 10 pesos and 15 experience plus weapon level 2. what this is going to do is take that single string this would be like a single string like this is gonna take it and instead of having that it's gonna create you a bunch of flail string like this and of course split them in different strings so we have that right now in our data data at the index 0 is equal to this data the index 1 is equal to this and so on so we're going to be using that value to change what we need to change okay so right now change player skin we can't do that we don't have any mechanic around it at the moment so we're going to skip it second up we have the what was it again was the amount of bezos so let's say pesos because we are in the game manager and it's you know it's right here we're going to change that value right there manually by saying pesos is equal to data at the index one now the problem we have at the moment is that data is a string and pesos is the end so we have to make sure we cast it first by doing int dot parse like this and this way pesos is now going to be equal to the end value of that string let's actually duplicate that we're going to need it for the experience as well simple stuff and finally change the weapon level which we cannot do at the moment and that should be everything we need to do at the moment for saving state so let's give this a try directly in the game i'm going to go and play this now one thing that i forgot that is going to happen at the very first time you boot your game um this this is going to happen simply because you don't have any save state at the moment and it wants to go further so before we do anything here let's check if player pref has key if you have the key actually if you don't have the keys let's make an exclamation sign in front of it save state if you don't have save state simply return we're not going to deal with the rest of that and this should fix the error okay so having this error fixed now we're going to give this a try in the game we have say 10 pesos let's make sure we hit a point where we can save the game so right here the game is saved and we now have 10 pesos we load the states again that's fine let's close it off press on play again and as you can tell on the right hand side over here we still have 10 pesos so this was saved forever and that's it so we managed to save our game and we can keep it through the scenes just by walking outside and doing our thing we might want to add some more function to it such as the destroy save so you can start over again and you know try this out if you do want to start over again in case you're curious what you could do is head somewhere say in your event like anywhere where the code is around so you could go in the awake and say player pref delete all and just by having this function call over here you should be able to press this it's going to put zero here because you're not loading anything anymore everything is deleted then you go back you can remove it and start fresh without having that um in the waiting mode and there is of course other way you can go about that you can go manually delete it in your registry you can delete only one key so you can delete that one key called uh save state and only delete that data in case you have other data you want to keep and that should be it for the savings section of course we're gonna have to come back once in a while to add our data in here such as the weapon level and also the preferred skin for the player now on the next one we are going to have a look at creating a floating text system this is going to be cool because it's going to let us know um say when we collect those chests it can say plus 5 pesos or something like that give a feedback to the player so he knows what happened and if we run into this guy he can say some text you know that kind of stuff also floating combat text so we could have damage displayed on top of our hits alright guys i will see you there welcome back in this new lesson we are going to learn about event and how to use them so in the last lesson we were looking for a way to actually hook these at the beginning of your scene and also at the end of your scene in this lesson we're exactly going to do that using events so let's go at the top here and actually have a look at the piece of code we'll have to deal with we're going to start with a scene manager this one is not going to be available so just type it out double click on it and then hit control and dot if you're in mono devlop oh sorry if you're in visual studio and make sure you do the using statement at the top if you're not in visual studio simply go at the top of your script and type in this using statement now we have access to the scene manager we're going to say scene loaded and you're going to see that this is an actual event so it has this little lighting sign then we're going to do plus equal the name of your function in this case load state now you're going to see that there is no overload for save state that matches the delegate which means save state is a function of course that is going to work but it does not match the the parameter that it should get so it says you need a scene and a load scene mode it says that at the very right hand side so we're gonna go down on our save state function and actually add those so it needed a scene we can call it s and also a load scene mode that we can call mode at this point you're going to realize that everything is back to normal and everything should work so what exactly is going on here we have this event called scene loaded and scene loaded is a event that the scene manager fires on its own so once you're done loading a scene scene manager is going to go through every single function you put in here as you can see over here we have the plus equal sign and then we have a function so what happens is every time that this event is fired it is going to look for all the function inside of this event so in this case same state and probably some others that we don't even see ourselves and it is going to fire all of these functions so it's going to call all of these function once the event is fired so you could have something else here you could have a load state as well and it would just load both let's give this a try so we're going to put this parameter in here to make sure it matches the the signature and then let's click on play and have a look at what happens now both functions were called save state and node state upon firing that event that and that event was simply scene loaded so once the scene was loaded it fired everything in here so what you can do just to prevent that from happening multiple time is go inside of the function you just created and just added to the event and inside of save state you can say well let's do minus equal once we're done once it has been called once we're going to remove it so in this case it did call save state because it fired the event and it was in it now if we were to load another scene from now on it is not going to do it it's not going to um call a safe state okay so now we managed to find the place where to hook our code at so this works we know it works the only problem right now is that it's inside of the save state when it really should be in the load state so let's swap that around and do it that way so now it's going to call load state instead we still have some trouble with the save state though like it is not it is not put where we want it to be we want to put it before we exit the scene or before we exit the game well for this to happen we need to find where we exit the scene and at the moment we only exit the scene at one single place in the code and it would be in the portal.cs so let's open up the portal.cs and when we once we actually put the player here in the scene management load scene we're also going to be calling the save state and now that is the beauty of the public static instance we've done at the beginning we can simply say okay manager instance save state and just like this it is going to work now remember that same state takes in those weird parameter which is like a scene any load scene mode since we're not going to be using them in in this event we don't need these parameters anymore so let's get rid of them and just like this we should be able to call save state okay so let's actually give this a try we move around we have the load state that just i was called a second ago and we're going to enter one scene it says save state which means we saved before going in now we don't have a load state for this one simply because there is no game manager in here if we did have a game manager in here then it would have been called alright so this leaves us with a single problem right now and it's really a decision you have to take do we want to be loading the game every time we enter a new scene or do we want to just keep that data with us everywhere we go this is two different approach that you can choose in between there is not going to be much different in the end actually there is going to be no difference in the end since it's really small operation that are not really expensive what we can do the simplest thing to do is simply copy and paste this game manager so copy head over to the dungeon one and face it in here now if you play this game you're gonna go here you're gonna have the save state and load state now of course we loaded the same scene so it's kind of hard to tell let's go back and here you go you're gonna have the save state and the load state inside of dungeon 1. this is something you could actually go for but since we want to make it as clean as possible we are going to get rid of the thing we just put and we're going to make sure our data persists in between the scenes so what we'll be doing right here is heading back into the game manager and in the game manager we're actually going to remove that call that removes this event so every time that we do load a new scene this one's going to be called and we're going to forget the fact that uh we're going to remove this so it's going to stay in there and every time a new scene is going to be called load state is going to be launched that is something we need to do in order to have this working of course we're going to leave this one at the top now something else we have to do in the awake call or as soon as you start the game is something called don't destroy unload our game object this is going to make sure that as soon as you start the game and as soon as you change scene the game manager is going to remain in here i don't know if you saw it just have a look on the right hand side in the arrow key when i press on play there is a new scene created called don't destroy unload and the game manager is on here which mean that if we go and get dungeon 1 game manager is still here and it still loaded the state even though we removed the call even though um there is no dungeon 1 there is no game manager in dungeon 1. so this is something that is going to help us keep the data now um there's going to be a bug if we load this scene here if we load the the main scene again which we will eventually you're going to see that we have two game manager and this is just going to create a lot of conflict so we must make sure that this does not happen at all costs again here there is multiple solution to this in coding there is always multiple solutions to go about fixing those little bugs but one i like to use and i tend to use most of the time is that i would have a scene before all my other scene i would have something called the pre-loader where i would put a loading screen i would put like a loading bar and um my game manager would be in that scene which means that this is one scene i'll be calling only once at the beginning of my game and i'm never going back to it so the fact that i'm never going back mean there is never going to be a duplicate of those objects output such as the game manager now there is also one more solution that we are going to use right here and it's to turn our game manager instance into some kind of singleton not the best one but at least it's gonna do the job um just fine so we're gonna do an if statement if gamemanager.instance is equal equal to null actually is not equal to null so if there is one already we are going to first destroy myself so destroy game object and then return making sure we don't run this go down here and that will result in um having a new game manager created once we load the scene but that one is going to destroy itself and we're going to keep the old one to prove this we're going to give ourselves some pesos so like 15 pesos and hope we get the right scene and you know what let's actually force it i'm going to just put one scene here called main and this way it is not going to break so we're walking in here as you can tell we only have one game manager and we still have our 15 pesos so this is exactly how we're going to fix this problem in the next lesson we're going to finally tackle the save state and the load state the content of this function in this section we are going to create a system that will display text on the screen and maybe give it some motion and we'll make sure to put it in a pool a pull is some kind of design where you can reuse the asset you've used in the past because you did not destroy them you only turn them off and this is something we'll be doing with our text because there might be a lot of it and we don't really want to instantiate a new asset every time so what we're going to do is instantiate one two or three asset and we'll turn them off when we're done with them and turn them back on when we need them again now the text i'm trying to create is a text that is gonna be a little bit complicated so it's gonna have its own logic that text is going to need to know if it's active or not is going to need to know how long it should be on the screen where it should be on the screen does it have a slight motion on it so does it move on the screen while we're displaying it and also what is inside of the text what's the color of the text what's the font of the text all of that we are going to create a new script that is going to contain all of that logic for a single text so let's go ahead right click on script and create a floating text object this is the first one we'll be defining in this lesson and it should be quite fast so let's start with a public boolean active this is of course to know whether or not it is being used at the moment next up we have a public game object that i'll call geo now this is going to be to have a reference to our very own game object and you'll see why it's useful in the moment once we implement the pull mechanic next up we have the text object so text i'll call txt now the text object is not something we currently have access to it is something we need to import and that is because of the the way um they added though the new ui system in unity they've done it after implementing couple things and they still haven't put it as part of the unity engine at the moment so what you have to do is do a using statement at the top unity engine dot ui you can either do that or of course double click on text press on control dot and find it in here and there we go now we have the public text txt next up is the public vector 3. oops motion we have the public float duration and public float last shown and all of these fields are going to be used in a single floating text object now this floating text object is also going to have public function the first one being public void show once we decide to show that text we're going to turn it on so active is going to equal true we're going to say last shown is equal to right now so time that time and geo that set active true or we can say set active active that could be something else we're also going to have a function when we need to hide it because we're not destroying it so we're not doing a destroy on the game object what we're doing is a simple active is going to be equal to false and geo set active to false as well or if you want active all right so we have a basic show we have a basic i'd now we're going to need some kind of update so let's do a public void update um something i don't want in this case since we're going to have a couple of floating objects i don't want this to be part of model behavior it's going to be too heavy well technically it's not going to be too heavy we can definitely handle it but just to make it clean we don't actually need it we don't need all that overhead we're going to keep it as a simple c sharp object and instead of having an update just like this called by unity we're going to have an update um called by us so i'm going to create a public function call it update floating picks and we'll call update floating text from some kind of manager in that update floating text we're going to check are we active or not if we are not active return we don't need to do anything if we're not active now if time that time minus last shown is bigger than duration we need to hide this text now this is one formula that i use most of the time so let's actually go through it real quick let's assume that time that time right now is 10 second in the game so 10 and last shown we started showing this object at 7 seconds in if that is bigger then assume that we have a duration of two then we're going to go ahead and hide it so you see how simple this is the time right now minus the moment we start showing this in this case that's three seconds um total if that's bigger than two which is the duration of the text we go ahead and we hide it so this is simply to know if we've been showing this text for long enough now if we have not we're going to say go dot transform dot position is plus equal to the motion times time the delta time so every single frame if we're still showing this because you know it's still active we are going to move the transform of our text by the motion usually this is always something like vector3.up so it's always going to go up a little bit all right so this is all we're going to need for our floating text now make sure you also remove the the mono behavior here we're not going to be using monobehavior in this case and that's it so in the next lesson we are going to create some kind of manager to instantiate to move to change the text inside of it to change the font and do all that kind of stuff so i will see you there in the next lesson hey welcome back to a new lesson today's lesson is going to be about the floating text part two so in this second part we are going to create one object one manager that is going to take care of all the floating texts that we put everywhere in the map so let's go ahead and right click on script let's create a new one let's call it floating text manager and of course open it up in your favorite editor now what we're going to do in here is we're going to create an object that is going to contain a list of the um the floating text and also um it's going to keep them in some kind of pull this way we can re-utilize the same exact object over and over again but of course every time we do change object every time we re-utilize one object we'll have to change the text inside of it the color of the font and um you know the position all that kind of stuff so let's go ahead and get started first off we're going to need two objects one's gonna be a game object called text container and the other one's gonna be another game object text prefab now what's going to happen is all of our text all of our floating text objects they're going to be in a um in an object that's going to be based off the text prefab and we're going to put them all under one kind of container so in the scene they're going to be ordered they're not going to be directly just put in the scene somewhere um you know they're gonna be somewhere clean then right after that we're gonna have a list so a private list of floating texts that is of course our class we've created ourselves let's call it floating text and initiate that list right away now in terms of function we're going to start with the pooling mechanic to create a pulling mechanic you're going to require some kind of object you want to pull in this case our floating text and also a mean to obtain them and this is what the function right here is going to do so private floating text we make sure to return a floating text at the end of this we'll call it get floating thanks simple like that now we're gonna start by looking is there any floating text available right now we could use and that is not active so that is hidden to do this we're going to create our floating text call it txt it's going to be equal to floating text the array and then we're going to find something in it so we're going to look using a predicate so we're going to say t equal then of course the arrow sign t dot active all right so now what this is going to do it is going to take the floating text array and then try to find one of them that is not active realize that there is the acceleration sign so we're looking for something that is not active in this case t right here t is some kind of enumerator so we could have said something um well basically this line could be resumed like this so it could be for loop and as long as i smaller than floating text dot count and then we do if statements so if floating text at the index i is not active then we would go ahead and return that one this line does exactly the same thing so let's keep the first line it's smaller it's more efficient and we're going to say if text is equal equal to null really important here so in case we don't find any here this is not going to crash this is not going to return an error no exception it is simply going to make text a null object so what happened is if we do find something we totally skip this and we can just return that something this way we just grab a random not random sorry we grabbed a floating text that is not active and we just return it this is what happened if we find one that is inactive now if we don't find one that is inactive we have to create a new one so here's what we'll do we'll say txt is equal to a new floating text and then we're going to assign stuff in it so txt.geo is going to instantiate and a text prefab so we're creating a new game object and we're assigning it to txt.go next up we're going to say txt.go.transform set parent and we're going to say that the parent of this new game object is going to be the transform of text container now there is also one more thing we need to assign if we just look at our floating text we need to assign the text as well motion duration in last shown is all assigned in here so we don't have to deal with that here um but we do need to have the text component assigned so this is what we'll do with the following so txt dot txt is going to equal the game object so txt.gameobject getcomponent type of text again we don't have the text right here so let's make sure we include the using statement so unity engine dot ui and finally once we created this new object once this object is set properly we're going to add it to our list so floating text dot add txt and we never remove it from there because if it is uh needed to have one more object we want to leave it in the pool we don't want to destroy it we don't want to lose the reference it's just going to stay there and if we don't use it it will be hidden and now just like this we have created a function that is going to return us a floating text whenever we want it whether there is some available or not okay so that's a very good start second up we are going to need a um a show function so public void show just like the text has one we're going to have one ourselves as well now once we do a show we need to pass in some parameters the parameters are the following so the text the message you want to send so we could call it message the font size color a color for the text a vector3 position a vector3 motion and finally a float duration so you see there is quite a lot of parameters but this is something that is going to help us customize the text in the game and of course is going to make sure we can adapt to any situation we want with that so what happens in here is first we need to declare a floating text so floating text txt we're going to get one from the pole so get floating text we're using a function ourself and now once we have one whether it is a new one or old one we need to put all of these parameters you see at the top here we need to fill that right inside of the floating text so we're going to say txt dot txt dot text now that is really i just realized that this is quite annoying to type uh it doesn't look very good so let's say floating text we're going to call that floating text with a small f and floating text dot text object dot text because there is a variable inside of the text component called text to change the message it's a little bit weird like that but that's how we d that's how we do it um that is going to be equal to the message so we're manually just changing the text inside of the text component here this is what we do now next up we're going to need the floating text dot text font size and if you realize that's why we have multiple that's why we have two layers in text text is the component and the component has a message you know that text message it has a font size it has a color we can actually have a look right now if you want maybe it would be easier to explain this way this is the text component right here inside of the text component there is text which is what we just changed so we changed that for our message and then inside of it there is of course the font size uh the font style you could change as well the font the spacing um all kind of stuff so we're really just interested in having the font size and the color and that's only for what we'll be using so text font size and color is all we'll be doing in here so i'm going to remove that canvas go back to the code that font size can be equal to one we receive in parameter so font size now next up we have the floating text dot text dot color it's going to be equal to the color we receive in parameter as well and then we have to mess around with the game object so floating text dot geo for game object dot transform not position and this is going to be equal to not just position because here is something quite new that i'm going to bring up to the table position in this case is a position in the world so assuming that you're 5 in x and you hit something want to display some combat text the text is going to be you know 5 in x but now that floating text is a text component and this one works on a different kind of coordinate system it works on a different kind of axis system i'll just try to explain this with the actual visual here as you can tell we have the player we're moving five in x actually that's 0.5 but you get the point so we have the transform position up here now our text is not going to be in the same coordinate system as this guy this one is in what we call world space in our case we're going to be messing around with ui and he has to be in screen space and screen space is totally different if we move point zero five uh in the screen it's actually going to move point zero five pixels so it's barely going to do anything you're barely gonna see it at the proper place which is why we need to transfer our world coordinate to screen coordinate and we will do this like that so we have to take the camera we're looking from in this case camera.main and camera domain is going to return any camera in your scene that has the um the main camera tag to it and by default it's there so in case it's not for you make sure that your camera the one you're using has the tag main camera to it when you create a new scene this is there by default so you should be fine technically if you remove your camera in the past you added a new one you were just testing out stuff make sure that it is on main camera right now okay back to the code once we do have a reference to that main camera we're going to say world to screen point and this is going to take your world position your say 5 in x and transfer it in screen space and of course screen space is the coordinate system that the ui uses so transfer world space to screen space so we can use it in the ui okay so one more thing completed next up we're gonna need some kind of motion so i'll just transfer that by saying floating text dot motion is equal to motion now um the floating text itself is gonna be taking care of moving it and finally not finally but duration next um duration is going to be equal to duration so these one are just there to transfer the knowledge from the manager to the floating text object they don't do anything right here they're not going to be used but the floating text himself is going to be using it and finally floating text dot show we're going to call the show function inside of it and just like this we'll be able to set everything we need instead of the floating text and show it on the screen so this is the step in between the show and the hide we did not have in the floating text okay we're missing one more thing and that one last thing is the update if we want to have some nice motion if we want the um the floating text to hide himself after x amount of time depending on the duration well we have to tell him um to update the floating text because he's not going to do it on himself if you guys remember we removed model behavior so there is no update available in here plus this is not even called update it's called update floating text um so what we're going to do is create an update in here because this one does inherit from autobehavior let's do a private void update and just say the following so for each floating text txt in floating text that's our array we're going to say txt update floating packs and this way we should be able to update every single floating text in the array every second sorry every frame and of course if this is not active they're simply going to break here and return so we don't do that operation down here all right so right now we have been coding a little bit too much without testing i don't love doing that so much but sometime it is required so make sure you tune in in the next lesson where we're going to hook up all of this um just link them together make sure we have everything in the inspector filled in and we can call the show function and see if the text does appear on the screen or not alright guys i will see you in the next lesson welcome back to another floating text lesson in this one we are going to hook up everything making sure everything is connected and ready to use so at the moment i am in my game manager it is now time to create a new reference right here we haven't created a weapon just yet that is totally fine we are going to create the floating text at the moment so let's call this floating text and just leave it like that once we have our reference we are now ready to call this somewhere down here so what's happening right here is we do have public function we can call from anywhere and um the show text function is something that we want to be calling from everywhere because any object really can use that function we want to allow the chest to say it we want to allow the enemy to say it we want to allow npc to say it and every time all of these guys want to say something we don't necessarily want to have a reference to the floating text object that is going to be in the scene so we decide to put it here in the game manager only at one place and we'll be calling it from here so here's what we'll do we are going to create a function if public void show text function then it's going to look very very similar to the one we have in um the floating text manager so i just realized that should be that should be floating text manager actually my bad small mistake here in my part let's make sure we change that um and also let's add stuff in here so the first was message the second one is font size third one was the color fourth the vector3 position fifth vector3 motion and finally the last one the duration so we we basically just copy the same exact thing we had in the floating text manager and we're going to call it so floating test manager dot show we send in the message the font size oops the font size the color the position the motion and the duration so the reason we're doing this like i mentioned oh mention sorry motion the reason we are doing this is simply because we don't want to have a reference to the floating text manager from everywhere we just want to have it at one place and the way we're doing this right now is going to allow us from anywhere in the code say the portal the portal could say well game manager that instance show text and then just send in those parameters from here and have the text shown okay so we are now ready i'm going to just type this as floating text and we are going to go right in the engine and link everything together okay so the game manager is right here we have the player which is not assigned the floating text which is not a sign let's uh since we're here let's actually put the player in here um and as far as the floating text manager goes we need to create it and this is where we have to right click create a new uh we could create a new panel right now and just remove the image change the name of panel to floating text and now we're going to add the component floating text manager we need two things here first a text container which is going to be ourself in this case because why not this is a this would be wasted game object if we didn't do that so let's drag and drop floating text put it in the text container but the field is here so in case you want to have something else another canvas or another container for say a smaller portion of your screen you could also do that here by putting it in the text container so we just made that available though it could have been private and we could have just used that very object next up we need a text prefab and this is where we'll need to do a little bit of work because we don't have a text prefab we never actually tried spawning one on the screen so let's actually right click create a new ui text now we have to make sure this one complies with everything we need so so let's go ahead and make this as big as we can so maybe 60 in height um we have to test out because if you go too far away on the font size say if you put a font size of about um 55 in this case this is going to disappear simply because we don't have enough space in height so if you want to have say a font size of 60 as you can tell now that this the actual text is not visible you'll have to up the height of your prefab um i don't think we're ever going to need something as big as that if we have a look on the screen right now on the game screen this is way too big i'm thinking about an average of maybe 30 in between 20 and 30 so maybe 25 and that will do job for me let's also make sure we have enough space in width let's say we write the long text such as hello little boy it's now your time to shine let's see how much width we need for this about 300 would be fine um i don't think we're gonna have text that big though so 300 in width 70 in height that is what i'll be using and i'll make sure this text is centered on both axis and i think that's pretty much it so this could be our text prefab right here once you're satisfied with your text prefab i'm going to rename it to floating text this is going to be the floating text manager and that floating text object the one with the the text component on it is going to be dragged and dropped inside of the prefab folder this way we now have a prefab just like we have a chess prefab we now have a floating text prefab which means if i delete it i can simply drag and drop a new folding text in there and it's going to be an exact same copy of what we just did that being said we are now ready to add it to our new field text prefab and try this out in the game right at the moment i don't think anything is going to crash so nothing crashes the only problem is we never really do anything so we never really called the showtex function let's do that with the chess why not start with the chess we're going to go down here where it says grand 10 pesos or you know you go back directly in your chess.cs file and instead of doing this debug.log we're going to do a gamemanager instance show text and let's actually send the text that we need to send so for this one i'll just do a plus sign plus the real amount so pesos amount and then pesos exclamation mark so that's going to be my text in the end it's going to be something like we had so plus 5 pesos like this oh we might want to add a space so it looks like this now what kind of size do we want i'm going to go with 25 we just said 25 is perfect so let's use that um in terms of color since we gain currency i'm going to go for a bright yellow so just color that yellow in case you want to have your own custom color you can create a new um color definition like this and just send in your rgb as you can see here they are not 255 base so it's a number in between 0 and 1. it's not a number in between uh 1 or sorry 0 and 255 so it's in between 0 and 1. in our case like i said color that yellow is going to do the job here what else we have the position we're going to use the position of the chest so transform that position because of course we are in chest dot cs so transform is going to equal to our own transform in this case in our own transform as chess is of course the chess transform motion okay so that is if we want to see the text move up down left or in any direction you want in our case it would be fun to have a slight up motion so we're going to say vector3.up and we're going to say times a hundred the reason i'm doing eight times hundred here is because we are in screen space and that is over a second that should be a hundred pixel up that might be a little bit too much now i think about it say fifty so every second we're going to gain 50 pixel in height next up we have the duration so how long do we want to say or display that text let's go for three seconds in this case everything in here is tweakable as you can see you just mess around with the parameter in case you don't like it so let's play this game see how it looks directly in the game oh we have a new reference exception and that is because i think our game manager doesn't have the floating text manager so let's make sure we fix that by drag and dropping it in the field second attempt plus 10 pesos as you can tell this is wonderful now it lasts way too long it might go up for it might go up a little bit too fast and it lasts too long so let's go back and tweak it like i said we're allowed to tweak everything we have everything we need here let's put that on 1.5 second make sure he goes up by 25 pixel and this is it so plus 10 pesos plus 5 pesos and here we go so that is pretty cool we have something that work and something that can be used to display the text so this is actually all we needed for the floating text section now we're going to be using this floating text in the future once we create our combat system once we make our little guy here talk we're going to be using that um you know as we progress in the course but now we have the based on if we want to actually call this room anywhere we know we can just do a game manager dot instance show text all right guys i will be seeing you in the next section where we're going to start tackling deep combat welcome back to another section in this one we will tackle the combat system now i understand that there is couple of things we left there such as the chess which does not really ground puzzles right now we get the nice text but we don't really have a change in our game manager so we understand that this is not completed just yet but we have to move on to the combat and we'll just connect all the dot once the combat is completed so we're going to jump right into making the combat first and then like i said connect those dots today we are going to go under artwork and actually crop out one of the weapon since we're here we could also crop out multiple weapons since we're going to be able to upgrade it so i'm going to go to the very top and we will start with a nice wooden sword now i'm not quite sure how big we should make this let's actually take the biggest weapon there is maybe this one over here and make it the size of the longest weapon when cropping this weapon make sure you take the largest one so this one over here and also the longest one at the same time so it's going to fit all kind of weapon i have something that is about 10 by 27 and it should fit everywhere we go we are going to start with this over here the wooden sword let's call this weapon zero once that is completed we're going to create another one of these bucks so 10 by 27 and we're going to move on to the rusty weapon so that's weapon one again let's move on one more step to the not rusty weapon make sure it is 10 by 27 weapon 2 and we are going to fix the crop now we're just going to keep going like that until you feel like you have enough weapon for your game enough um enough of those i'm gonna actually we have what zero one two three i'm going to take this one next let's also make sure it is 10 by 27 that's weapon number actually number four but that's the fifth one and then i'll move on to the golden weapon down here then 27 that is weapon 6 or sorry weapon 5 and finally the last weapon there is going to be is this one that's for my game of course if you want to have something different you can have something different and i just realized that this one is a little bit bigger than all of the rest so i'll go back and actually change that to 10 30 for every single one of these because i think this one could fit in a 10 30 yep it does so let's make sure we change that to 10 30 for everybody here we go okay having this completed we now have sprites for every single weapon we'll be using in this game you could of course went here for daggers for the hammer for different colors but these are the six i'll be using starting from the wooden sword the rusty sword the normal one the normal one with a handle the long sword golden one and the golden long sword so now that we have these we are going to create a new script called weapon this one is always going to be the player's weapon we're going to make sure that this weapon is actually beneath the player's object so i'm going to scroll down find weapon 0 and drag and drop it beneath player we should now have something like this the weapon is going to be beneath everything we have to make sure that it is on the proper layer so i'll actually go here add a sorting layer let's call that weapon and projectiles but we'll just use that for weapon right now and put it on top you're gonna see that it pops up right here now we're going to play with the size and the positioning of this so i think i'll be putting it right next to the ed um just be really careful with the size because it is going to be affecting the gameplay as well and we could be using something like that now in terms of the sorting layer we'll have to fix a lot of distorting layers in the future such as um this bug over here where we're behind the actual chest it's all the thing we have to fix and we will do that later on right now let's just have a weapon in our hand and that weapon needs to have a collider as well so we're going to go here and give it a box glider 2d if you click on it you're going to be able to see the whole distance it covers and this is pretty cool this is pretty accurate we want to have it a little bit um bigger but if you don't you can also just reduce it like that but in my case i like to have it a little bit bigger this way is going to be easier for the player to actually play this game and it's really up to you and your difficulty level in that case okay now let's get started scripting this thing we're going to go on the weapon and actually add the weapon script to it the new script we just created let's open it up instead of our favorite editor and guess what we're gonna do we are going to get rid of monobehavior and make this a collidable object just like this now if you remember making it collidable means we can override the on collide function and actually know what this weapon is colliding with which is going to be really useful one once of course we know which person we're going to attack all right we're going to start with a couple of field as always i'm going to start by declaring a little section at the top that i'll call damage structure public int damage point i'll make that equal to 1 at the beginning and then public float push force equal to 2.0 this one are going to be used once we transfer the information so once our weapon collide with an enemy we're going to transfer that information to the enemy to know how much damage he taken and also we're going to add a push force on top of him so he can actually be pushed away from us next up we're going to have a upgrade section because our weapon is upgradable we start with a wooden one and in the end we're going to have the golden weapon so we'll go here make a public and weapon level i would usually make that private but we're going to be using it from the game manager as well to do the saving to do the upgrade a lot of other things so this one's going to be public in this case and also in terms of upgrade we're going to need the sprite renderer this is so we can actually change the sprite of our weapon just like this now the sprite renderer is private so we need to actually assign it in the start but if you remember inside of the collided bowl we already have a start this one is virtual so we'll have to override it if we want to use another start back on the weapon we are going to declare a protected override void start and we'll keep the base dot start because we need to assign our box collider so we have to keep this whether we transfer the code right here or we keep base dot start it's up to you mine i'll just like to alternate i'll just keep this base dot start this time then we'll make sure we have the sprite renderer is equal to get component type of sprite render simple so we're simply getting the component called sprite renderer which is also on top of our weapon it's right here the reason we're doing this is so later we can say once we upgrade we can say okay now your weapon underscores zero well just become weapon underscore one and then two three four five and six in the end all right so we have all the field we need right now for basic logic the next mechanic would like to implement is the swing so really simple swing you just swing the weapon in front of you it is going to attack the people in front of you and you'd like to you know take more space in the screen that what it's already taking right now so what we'll be doing is we'll go down here and we'll just add a new section of variables first one being private float cool down so how often can you swing what is the cooldown i'll say 0.5 here so you can do a swing every 0.5 second then a private float last swing this is going to be used with the cooldown to know if you can swing or not and we will be testing that in a update so protected override update again we are going to keep the base.update because based on update in this case is the one doing the collision work we were not allowed to get rid of that we need that to be running uh simply because if you don't have that running then we're never going to be able to call the on collide function which again we will need in the future the only um kind of mechanic i wanted to add in the update is to check whether or not we're allowed to swing so if input get key down and we are actually hitting say spacebar so keycode.spacebar spacebar will be our key to attack to swing then we'll check if the moment right now if the time at this moment minus the last time we tried to swing is bigger than the cooldown that means we can now swing again so last swing is equal to time that make sure we reset that and then we will swing swing as a function hasn't been created just yet so let's go ahead and create one private void swing here we go we will go down here do a debug.log and just say swing at the moment so we have pretty much everything we need we're only missing one thing in this weapon script we're missing the override on the uncollide function so once we do collide um with the enemies we're gonna have to create something where i have to create some kind of damage structure and send that over to the enemy we will be taking on this task in the next lesson right now i'd like to just go over what we have at this moment so we have some field at the top here that are going to be bound to the weapon but they're also going to change once you upgrade once you upgrade your weapon you'd like to increase the damage point you'd like to increase the push force so once you do hit your enemy it's gonna be push further away it's gonna eat more damage and then the upgrade right here some other field we'll be using from outside really important that we keep them public because the game manager use it to save and also the upgrade weapon menu we will have in the future is also going to read this value sprite renderer is only here so we can have a reference on the weapon and we can just change the sprite change the visual aspect of it and finally we have the swings so these two float over here are for us to just monitor if we're able to swing right now or not and that's all we do in the script right down this moment we have a weapon that we can swing every 0.5 seconds and we just have some extra stuff for later so that's all we have at this moment in the next lesson we are going to create the link in between the player and the hand me when it gets it so you're going to be able to override the on collide function this way uh the weapon you have right now is going to send a message over to the enemy and that enemy can now aid some damage all right guys i will see you in the next lesson welcome back to another lesson in this one we are going to create the on collide function we're going to override the uncollide function this way our weapon can actually affect the enemies and so on so we're going to go ahead and lay down the base work here with a protected override and we're overriding the only function left we have to overwrite which is on collide we already overrided the thought update now we're going to do it for uncollide and let's check do we need to actually keep the base in here there's only a debug.log so we're not going to keep it let's actually get rid of it and at this point we need to check is our weapon colliding with another actor another fighter another player another object that moves around and has hp and we really don't know that until we tag them all so this is what we'll be doing we're gonna go back in the game engine and make sure that everything that we can actually hit with our weapon has a tag so let's have a look at the player right now there is a tag the tag is on tag and that's not really cool we are going to start ordering everything that we can hit with our weapon with a specific tag we'll call this one fighter just like this and let's make sure that the player is now a fighter because he can also get hurt we can hurt people with our weapon but the enemies can also hit us the player so we have the player in here we're missing something we can hit and we could technically put the test npc in here and just have it go at him but let's go ahead and actually crop out one enemy let's go under the atlas and find some enemy we'd like to kill so which one would be the best we need to start with a small one and i'm gonna choose this one at the top here this one is really clear looks good let's actually take him and uh you could technically put it into a 16 per 16 as well if you wanted i think everything should fit within a 16 16 block so let's have a look yeah everything seems to fit within that so let's go ahead and use a 16 burst 16 and i'll just make sure to anchor it at the bottom so that's going to be enemy number one so enemy underscore zero let's hit apply and put this guy somewhere in our map why not right here it doesn't show up simply because it is on the wrong sorting layer so let's fix that it's going to be on the actor sorting layer and we now have our very first enemy it looks awful but that will be it now at this point we need to put a box collider on this thing so let's go ahead and do that box glider 2d if we expand it it should take the proper shape if you don't like that let's make sure you actually edit the collider i'll just take his head in there why not he has quite a big head so he'll be able to uh he'll be easy to hit anyway and here we go now we have to make sure the tag is fighter and the layer is actor okay so let's go back in our code real quick and under on collide we're gonna say debug.log collider.name we're going to have the same exact thing as we had earlier so let's play this game as you can tell our weapon right now so our weapon is actually hitting our player right now this is another condition we will have to add in the future but let's walk toward this thing see if we also get his name and as you can tell in the console.log you also get the enemy zero so we are able to hit him and what if we go next to the test in pc we're still able to hit that guy as well now we have to filter both the player and the test npc the way we're going to do this is like this we're going to go inside of the code and wrap this around a if collider.tag is equal equal to fighter that's going to be the first one this should get rid of the test npc but we're still not getting rid of the player because the player has the fighter tag as well so we'll do if collider.name is equal equal to player then we can actually go ahead and transfer our damage structure which we don't have right now but let's just imagine we do with that debug.log so we're going to walk around with our sword and for some reason we are still hitting the player why is that oh i actually typed that wrong the logic is flawed over here i said if the tag is fighter and if the name is player we have to actually turn that around to a is not player or what i like to do better is to actually say if it is a player then we just return something like this could also work okay all right so let's try this really quickly in the game we should not have anything in the log except the enemy zero here and we don't as you can tell it is only the enemy zero we're not getting the player call we're not getting the weapon call now if we actually go back on this test and pc you're gonna see that we still get the weapon and we get the player but this is for another reason this is because we never actually change the basic um the basic call inside of the on collide now let's go ahead and just add another message to this so we actually know that this is the basic on collide so we're going to say something like on collide was not implemented in we'll do this dot name this way you're going to be able to know which object has not implemented on collide has not overridden on collide so if you walk on this guy you're going to be able to see uncollided was not implemented in test npc and if you go over to this guy you're only getting the name because that's the function we overrided okay so now what else do we have to do at this point we actually need to send that message as a structure so we have the option to send it in many way we're going to be using unity send message function and to do that we'll have to wrap everything that we want to tell the enemy into a single class a single message to do this we're going to go back create a new script and that new script is going to be called damage so let's right click create a new c-sharp script call it damage and imagine this as the container of your damage imagine you're sending out a fire arrow in some game well that that fire arrow is going to contain the amount of damage it's on maybe where it started from to calculate its velocity it's also going to contain uh who sent it at first so you can attribute the kill to the right person well this is this is kind of what we're doing right here but it's going to be on the smaller scale that damage structure is only going to contain three field they're all going to be public the first one is going to be a public vector 3 called origin the second one is going to be public and damage amount so how much damage do we transfer and finally a public float push force now um what we're going to be doing with this is we're going to push the receiver using push force and also the origin so the position of the receiver and the origin we're going to have a direction out of that and then we'll just push that guy using push force we're also going to deduce the amount of hit point he has by damage amount alright so let's go back in the weapon and send this over to the enemy so we are going to create a new damage object and then we'll send it to the fighter with hit to do this damage dmg is going to equal to a new damage object and we can just assign it directly of course we could do damage like this and then say damage dot damage amount is equal to x but you can also assign it manually just like that at the same time you create your object so let's remove these and just say damage amount is equal to damage point damage point being this thing at the top here also our public field that will be changing and those take combat they don't take a semicolon the origin of the damage is going to be transform.position so our current player position and then finally the push force equal to our push force let's make sure we put a semicolon on that and we now have our damage structure all that is left is to send this over to the enemy and we can do this this way so collider send message and now we have to send a message you need to send a method name and finally the structure so object value over here so the method name is going to be receive damage the object value is going to be our damage structure and just like this we are now going to send this message over to the enemy this is not going to work just yet because if you have not realized receive damage is not a function we have either on the enemy or on the player itself receive damage does not exist at the moment and it's something that we'll actually address in the next lecture so if you try to run the game right now you'll be able to run around you'll be able to create your damage structure but as soon as you try to send it to it in me you're going to have this message the send message does not have a receiver that's completely true and in the next lesson we're going to do a little bit of inheritance again to make sure that both our player and the enemy can have this function welcome back to another lesson today we're going to make a script that is going to be inherited from our player and also the envy this script is going to grant them hit points and also the function receive damage so we can actually complete the mechanic we started in the last lesson so let's go ahead and right click on script create a new fighter script open it up in your favorite editor and we're going to keep mono behavior so our initial model behavior is going to be inherited from fighter and then player this thing over here is also going to inherit from fighter no longer model behavior but now we're going through this so we can inherit the following we're going to need a couple of public fields first one being a public end hit point then we'll have a public and max hit point and finally a public float push recovery speed let's make that 0.2 f the hit point could be on say 10 by default it points gonna be the same and then we're going to have some field for the immunity we want this so this way you can't actually just spam your hits on the enemy or you cannot get corner and just kill instantly so we're gonna have an immune time this way you have like say one second to get out of problem if you are stuck we're also gonna have a last immune so this is going to act the same exact way as the last cooldown and the swing we just implemented on the weapon now a little bit more we're going to have a protected float for the push so protected vector3 push direction okay so at this point we have all the fields we need we're going to implement the function all fighters should be able to receive damage so all fighters can receive damage and also die so we're going to need two function here one is called receive damage and the other one is going to be death or die so we're going to start with the first one protected virtual void receive damage and it's going to take in damage structure just like we sent earlier now um we're also going to need another function this one is going to be called def or die so protected virtual void def and if you realize i made those virtual so in case you want to change things around in case the player has some kind of special armor or like a shield you can override that if you want in the player script okay so by default what should happen if you receive damage by default we're going to check if time the time minus the last time you've got hit so last immune if that one is bigger than immune time then we're gonna allow you to receive damage so last immune is gonna be equal to time that time hit point is going to be minus equal to damage to the damage amount and then the push direction is going to be equal to some kind of formula we're going to create right now so we want to have the direction in this case the direction you should be pushed towards to now the damage structure contains the origin of your damage but it does not contain your position you're going to have to calculate that yourself by doing a transform.position minus damage dot origin this way you can now have the vector in between you two normalize it and add it to the damage dot push source this way you're going to have your vector normalize and then we'll multiply it by the amount of push force the weapon uh the enemy use to push you okay so just like this we should have everything we need in the receive damage uh we're also going to be creating a little check down here so if your hit point goes below or equal to zero that's actually called def so if it goes below really far like minus four minus six let's make sure we reset that to zero but we're also going to be calling the def function something we'd like to add just in between here is some kind of cosmetic some kind of visual effect to let you know that you've been hit so we could have particle effect in the future but right now the only thing we have that we can put is the show text remember we have this nice floating text thing so we'll say game manager that instance show text and now the message is going to be damage damage amount to string so we're actually removing that amount and then we'll say the font size could be something like 15 color could be red the position is going to be our position and the motion could be a vector 3.0 in this case we don't really want it to move why not we could have it for say 0.5 seconds on the screen alright so now to make this work in the game we're going to need a proper receiver right now we have a receiver on the player that is totally fine but we don't have one on the enemy so let's go ahead and create a nv script as well since we're here we're going to create a new c-sharp script call it enemy put it on our enemy underscore zero go in the script and make sure it inerrates from fighter we're going to wipe these two functions just leave it like that and now try this out let's see if it does work once we're playing a game we're gonna run into that enemy and it's gonna say one as you can tell really small one we could increment the size of it and it should actually work just fine okay so at this point the enemy should be should be down in hp if we have a look here on the right hand side the enemy has three hit points and as we keep running into it you're going to see the hit point go down so knight reaches zero it should have called the dev function which does nothing right now we also have a bunch of warning over here so let's double click on one and check out what is wrong it mentions that we're trying to create a new monobehavior object and the best way to create a model behavior object is to do it instantiate now they are totally correct we should not be doing it this way if it is a model behavior object but in in our case it doesn't have to be so i will go back on the damage structure over here and actually get rid of monobehaviour and you know what we can even turn this into an actual real structure since we're here this way we don't have anything to worry about anymore we won't get that warning anymore so let's try and run this once more and here we go we get the plus one on this little guy so i'm going to go back on the fighter real quick implement a bigger font size so say 25 this way we should be able to see it a little bit better so we did one damage to this guy okay so now this enemy is finally taking damage of course it doesn't fight back of course we're not getting any damage but at least we made a really good step towards making this combat system work and we finally have some damage on the enemy he receives our messages in the next lesson we are going to add another layer to our inheritance um in this case we're going to be adding something called mover in between fighter and player this way we can have mover have object move around and and me can inherit from that as well so now both thing can move the enemy can start moving um as he wants once we're done implementing this so i will see you in the next lesson welcome back to another lesson guys today we are going to implement another layer in the inheritance tree so we're going to go and open up player and actually make sure we get rid of most of the code in here in the fix update we're going to be delegating that to another script that we'll call mover so we're going to right click on script call this one mover and this one is going to inherit from fighter so everything that move can also fight in this case which might not always be the case since you might have npc that are only there to help you but if that ever happens we can make them immune forever by overriding a couple of fields okay so in here we're basically going to take whatever it was that we had in player um everything that was used to move around we're going to put it in here so let's have a look at what exactly that was we have the move delta the box collider and the hit this is all used to move and we might add some more such as the speed and x the speed and y we're going to be moving that so let's actually take all of this actually well you know what let's actually take everything so let's scrap everything that is inside of the player and put it in the mover object there's going to be a couple of things we need to remove such as the the inputs over here simply because the enemy is not going to be using these so let's go through that quickly we're going to need a bus glider that's fine we're going to need the move delta that's also fine a hit we're going to need a protected float y speed we'll put that on something like 0.75 protected float x speed i'll leave that on one so we're gonna have the same exact speed as we had before except when we're going up and down let's also make sure that everything else all of these other fields are now protected because we might want to be using them in player now the start is going to stay the exact same though we're going to make it so you can override it so protected virtual void start now the update is going to be quite different what i'd like to do is actually split the whole updating of the player position and um actually keep it somewhere else so what i'll do is i'll just take everything in here except the inputs i will be creating a new function and i'll call this one protected virtual void update motor this one is going to take in a vector3 input and this is what is going to differentiate the player from the npc the npc is going to have something pre-calculated we're going to send it the input it wants to go in and the player is going to be having the keys we send him through the inputs now i will make sure to copy everything we've had in the past and just put it inside of the update motor whatever we were receiving at the top here is now input so when we say move delta is equal to a new vector with the inputs in it we replace that completely by the input field we receive in parameter the same exact logic is applied everything works as it was working in the past now we have to do something about the fix update and i really don't feel like doing anything with it to be honest since no mover object is going to be put on the fields i'm saying by this is that no object is going to have the mover.cs script on it everything's going to be either player or enemy and these two are going to inherit from mover but mover itself i don't think we'll ever see that in fact if we are certain that we're not going to be seeing the mover script anywhere what we can do is make this class abstract by putting this abstract what is going to happen is that you're not going to be able to drag and drop this on any object from now on it has to be inherited from else it just won't work so let's go ahead and grab these two over here crop them out remove the fix update and go in our player object we're of course going to change that for mover now don't worry we actually keep the fighter as well because mover inherits from fire so it looks something like this and then so on so behavior object blah blah blah and what we'll be doing in here is we'll create a private void fix update and in that fixed update we'll say well float x is equal to our input float y is equal to our input then we'll do a update motor with those inputs so new vector3 x y and then zero and just like this we should be able to transfer all the code we had in the past and our player should behave the exact same as it did so let's actually try this out in the game see if we haven't broken anything and everything still worked just as it was working before so this is fairly cool um one thing we haven't implemented though is the y speed so we still go at the same exact speed as we were going before so i'll go back in here and i'll make sure to change that as we reset the move delta with input we're going to change that and actually allow us to change the speed of both x and y at the same time so i'll go in here create a new vector 3 and use input.x and i'll do times xspeed and then input.y times y speed and finally zero on the z axis this way we'll be able to implement the speed in here and we should not be going as fast up and down as we're going left and right which is the case right now i can feel it we don't go as fast up and down as we go left and right and everything should be back normal we now manage to create a layer in between our fighter and our player we will be applying this layer on the enemy object in the next lesson welcome back to another lesson guys today we're going to have a look at the enemy and how to give it some kind of ai give it some kind of logic to run it towards our player something very very simple and it's going to require a lot of fields but we're going to make it work in um in a really easy way so it's not going to be that complicated to understand but it's going to be big in code so let's actually get started right away by opening up the enemy script at the very top of our script we want to change the fighter to mover we are now inheriting from mover because our enemy is now able to move now um there could be another thing in here we could create a target dummy that could die and you know have hit point have the receive damage function that would not necessarily move so you could create some kind of target hit point uh sorry target um dummy dot cs and just make it inherit from fighter that could also work but right here we're talking about a real enemy that is going to move on the map so let's actually code this right now we're going to start with the experience little section all we have to do for the experience is declare an amount of xp this target is going to be worth so in this case one xp for this target this is public so it can be changed directly in the inspector now in terms of the logic we're going to create a couple of logic fields in here first one being public float trigger length put that on one and then a public float chase length and i'll put that on five the trigger length is going to be one meter that means if the distance in between the enemy and the player is less or equal to one meter we're going to make it so he starts chasing you now how long is he going to chase you for he's going to chase you for five meters and if you exit that initial range of where he was and um where you going right now if that length is bigger than five then he's going to go back to where he belongs those are the simple logic we'll be adopting for this very very simple enemy we're then going to need some private field private boolean chasings are we chasing right now um also another private boolean colliding with player and i'll tell you what this is in a second and private transform player transform oops and in a private vector3 the starting position okay so chasing is going to be ebolian to know whether or not the enemy is chasing the player right now colliding with player is going to be a way to know if currently you're colliding with the player now if you are colliding with the player don't move just keep on stay there you're going to be hitting him anyway um if you're not colliding with the player that's fine you can go towards him but if you are already colliding don't go towards him it's going to create some awful bug it's going to be really hard to test collision at that point so we're going to make sure this one stops there and that will be all handled through our logic that we're about to lay down right now now before we go any further we also need one more section and that's going to be a section that is about the enemy's weapon remember the player has its own weapon it is a whole different class it is going to be the same exact thing for the enemy but this one is going to be a hitbox since the enemy doesn't have a weapon and it's on it's not swinging at you it's only going to be there and dangerous if it touches you so we're going to use the it box right here now that hitbox is going to have an additional collider so private box collider 2d that's going to be the hitbox and then we'll have also to do some collision detection and here we cannot inherit from collidable unfortunately so we'll have to create our own little logic in here and you'll see why um the reason we can't inherit from collidable is because we're already inheriting from something and that is that is just part of a c-sharp so we cannot have multi-inheritance we're simply going to duplicate that very small chunk of code so to to actually have this uh colliding mechanic work we're going to need a collider array polarity 2d array called hits new collider array of 10. we're gonna do the same exact thing as we've done for the weapon for the chess for the npc and such so now that we have all the field we need we are going before we go in and um type in the start the update and everything else we need we're gonna go and create that hitbox we're talking about so we already have the player hitbox the end me hitbox which is just the size of its head at the moment we are going to create a additional hitbox on top of that that is going to be the damage hitbox so let's go on the enemy we have it right here i'm going to call him small enemy so small enemy and beneath him then i'm going to create a new 2d object a new sprite we don't have to keep the sprite renderer actually we don't really want to put anything in there um just temporarily i'm going to put the chest i'm going to add a box collider and then i'll remove the sprite renderer this way i can have a proper size collider now we're going to shape this collider bigger than the small one so bigger than just the head and we'll be able to see them both in action in a second so let's call this one hitbox now click on the small enemy you should be able to see the two collider one of them is really hard to tell right now you can only see it through the eye really but the head shape is gonna be where you you're allowed to hit this small enemy and the the whole box around it is a hitbox so if that touches your player you are in trouble we could actually do it this way so it's a little bit easier for the player the head over here would be the hitbox and the head inside so the white part could be where your sword has to hit in order to be a real hit okay now our hitbox are ready we're going to start laying down the logic and we have a couple uh line of code to do that we're going to start with a protected override virtual void actually protect override void uh start not def start and in the start we'll do a base does start because we still want to be using what's in the base so we still want to have the box collider from the mover and then what we will be doing is getting assigning some of these at the top here so we'll be assigning the player transform the start position and also the hit hitbox let's start with the um the player transform player transform now the player transform is going to be equal to the transform component on the player and there is multiple way to do this you could say game gameobject fine player dot transform we could do we could do game manager instance player dot transform you know you can find your transform in multiple different ways if you want to we'll keep this one it's cool because we assign it manually through the game manager the next one is going to be the start position it's going to be equal to transform.position this is called on the start so wherever you place your enemy in your map that is going to be their starting position as soon as the game is launched then we have the hitbox and this one is a little bit complicated because if we do a get component uh bus collider 2d this is going to return us our boss gliders the lil head the place where we can get hit not the hitbox the hitbox is actually below house on a children so we'll do transform get child at the index 0 the first children and then we'll do a get component this way it's going to do this exact same thing here so it's going to go it's going to start from the small end me and say okay we want to get the first children so let's go down and then do a box glider 2d so we grab this one next up we are going to override the fix update so protected overwrite void fix update and i don't see it here so oh right we didn't actually include it in the mover so we have just to create a private void fix update that will do the job i was about to override it but i realized that we did not put one in the mover we just completely got rid of it since it's now abstract so in our private void update well we have to the update motor at one point so let's actually leave it somewhere here update motor vector3 0 for now so we're updating the position of the enemy right now we still don't know what's going to be in the input okay now at this point we're going to have to look is the player in range and if he is not well we don't have to move because the player is not anywhere close we don't need to chase him so what we will be doing here is check whether or not the player is in between um our starting position and the biggest distance of the chase so the chase length we'll do that using a vector3.distance so if vector3 the distance in between the player transform that position and also our start position if that is smaller than let's say the chase land then we can go ahead and check are we chasing him right now because this is going to be possible from 5 meters away however we want this to be we only want the trigger to be at one meter but if you go away while he is triggered while he's tracing you you will be able to run for five meters before the chase stops so we're going to do another if checking here if the vector 3 that distance using the player transform.position and also r start position if that is smaller than the trigger length at this point chasing or chase or whatever the boolean was so chasing it's going to be equal to true or if you prefer what you can do is also say remove the if statement and just say chasing is going to equal to the result of this condition now if we are chasing so if chasing now let's assume that we are chasing the player if we are chasing the player we're going to say if we are not colliding with him if we do not collide with the player let's update the motor in such way that we're going to run towards them so we're going to say update motor and we're going to use a directional vector using player transform that position minus the transform.position dot normalize and just leave it like that so it's going to go in the direction of the player now if we are not chasing we'll do it else statement and that l statement is simply going to be update motor with the start position minus the transform the position so we go back to where we were okay now if the player was not in wrench in the first place we have to reset the tracing we have to reset this thing here so we'll do else statement and we'll say update motor start position minus transform the position again so we're going back the same exact way and we'll see chasing is now equal to false and we won't need this thing anymore so whatever happens we are updating the motor the only thing missing in this algorithm is the colliding with players so we never really know whether or not we are colliding with the player and this is something we'll check inside of the fix update so just after everything is done we're going to check for overlap so check for overlaps and we're going to say colliding with player is going to be equal to false at the beginning and then we'll actually do the exact same thing we've done in the collidable so if we go here i'm going to grab this thing go back on my enemy.cs and paste it down here so box ladder overlap collider um do we have a filter right now i don't believe we declared a filter we should have declared filter i don't believe we declared a filter so let's go back and declare one we're actually going to need one so um in the head box over here we'll say filter 2d so contact filter 2d call it filter and now that should work then we're going to do the exact same thing as we're doing before if the hits are null we don't do anything now instead of doing a on collide we're going to do our condition right in here if hits at the index i the tag is equal equal to fighter so if we're colliding with another fighter n hits at index i dot name if that fighter is player then we are colliding with the player so colliding with players going to be equal to true and again we make sure we clean up the array once we're done okay so that should be it for the actual logic behind our enemy we are going to need one last thing and that one last thing is going to be to reward the player when he kills the enemy so we're going to override again another function so public override death and once this thing dies so as soon as the enemy dies we're going to destroy it so destroy game object so now the game object the enemy is out of the game it's out of the actual scene that's quite good but that's not really um satisfying we're gonna need more than that and what i mean by that is we're going to need to first create some kind of way that we can give xp to our player so we can say the manager instant experience is plus equal to the xp value that could be it and also let the player know that we gave him xp by showing text so game manager instance show text and we can do something like a plus sign then the xp value give a space call it xp and say fun size is going to be 30. color could be magenta transform that position vector 3. up this one could go up by say 40 and it can last a full second okay so a lot of code we haven't tested this out hopefully everything works in one go let's go in the game and this little guy over here should be triggered in a second you will be able to see it there is the maximum amount of hit point which is 10 a little bit too much so let's go ahead and reduce that to say um two or three the push recovery speed is not going to do anything right now since we have not implemented it in um the mover but we'll do that in a second as well xp value could be one uh trigger length is fine chasing this fine so if we start playing this technically oh it is actually running towards me so that that is kind of bad at the moment but let's see if we can do something with that so i just realized that one is quite a big number in this game this game is quite small if you remember we had to scale it down to 0.16 so this is a very very small game let's go ahead and change the trigger length to something like zero point um three and the trace line could be a full meter now a full meter for this game is something like this starting this position and going there okay so the position it was at the beginning to where it was right now that's the full meter now 0.3 we should not be in it technically we might be okay so we're not if we get a little bit closer it's gonna do something it should be doing something so there is definitely some kind of mistake here but we did kill him we did get one xp uh does it actually work is it actually showing in the game manager yep we have the plus one experience over here now we just have to fix this whole um chasing mechanic which is not working as intended at the moment all right so i found what a problem was over here i've made a little mistake so i said chasing is equal to this but that's not actually true um we want to make sure that chasing is only set to true here because we have our own place where we set it to fall so we only set it to false if we're outside of the chase length in this case if we do it this way it triggers it actually puts it back on false if it's outside of the trigger length so we don't want that we are going to change this turn us into a if statement and then say that if this is true we're just going to say it's equal to true we're never going to set it on false um at this point this way what this is going to give us is this behavior over here so we have a trigger length that is a 0.3 which would be just about here where my cursor is and then he can chase me for three meters which is i think the whole screen in this case so as you can tell he chased me everywhere we go now um he still doesn't hurt me i can i can hurt him by doing pretty much anything just turning around is going to kill him right now um but we're going to be creating a weapon for this guy in a moment but at this moment um if we actually go back in the values put that on say chase lane could be on one and test this out this is going to happen right here so if we go too far away he goes back to a starting position so that is what we could actually do with this guy uh in terms of giving ourselves some xp as you could tell it did work so i'm going to choose my game manager experience is on zero right now we fight him we get one point we have one experience the text was shown and the enemy got destroyed in the next lesson we're going to fix these two problems first off we cannot get hit from the enemy only us the player can hit the enemy it's not the other way around and second we're never getting pushed away so if we do hit the enemy or if the enemy hits us um the person that got hit should be pushed away by the weapon we should actually have a little bit of sliding in the opposite direction so this is what we'll be doing in the next lesson guys i will be seeing you there welcome back to what should be the final lesson of the combat section so in the previous episode we made the combat work a little bit we still needed the player to hit us and also have some kind of pushback which is what we're going to implement right now we're going to start with the fact that the player can never hit sauce the reason he can never hit us is because he doesn't have a weapon the weapon should be his head but right now it's not doing much so what we will be doing is to turn this hitbox over here into a weapon how we're going to be doing that it is quite simple we're going to start by adding a new component call it enemy hitbox and that's going to act as the quote weapon let's open this one up and we're going to inherit from collidable so again this collidable class is coming to save us all from writing that big long code we don't want to write every time okay so at the top we're going to have a damage section public int damage and then we're going to need a public int or we could do a float here push force that's all that's all we need in here that's our simple weapon at this point we need to override so once we do collide with something we override the on collide and we do not need the base remember the base is only debug.log your really annoying one so we don't need that in this case we need to check whether or not we've hit the player so if collider.tag is equal to fire n the call dot name is equal equal to player in that case we are a hundred percent sure that we hit the player we could have only did that but like uh with the fighter tag we also have the additional confirmation so it's up to you you might want to remove this it's it does not really matter it's just an additional check in case you have another object called player okay so we're going to create a new damage object of course before sending it to the fighter with hit in this case the player so to the player same exact thing as we did for the sword so where is the sword at where is the weapon.cs at we're going to be taking this and copying it in the enemy hitbox i think that's it i think we actually got all we needed let's make sure we match those so damage amount is going to be equal to our damage right here um transform the position that's fine push force is also fine and we send a message receive message is the same exact function as the one the player has so we're actually done we actually created a weapon just like this it took what it took even two minutes three minutes and we're already good to go so let's actually play this i'm gonna get close to this thing and if you look on the left hand side over here we are getting hit by uh zero this this thing doesn't have any damage on us let's actually bump up the damage shall we let's put that on one hey we are now heating one damage at the time let's put that on five eating fight damage at a time and we should pretty much be dead by then if we have a look at our player player script zero hit point we never override the def function on our player we don't do that just yet we'll do that later on during this course but we are dead the only thing left to this thing is some actual uh feedback more than just the level 5 on top of us we need to have something else in this case that is going to be the push to implement the push is going to be so simple we're going to head over to our mover script because this is where you would implement something that goes in both the player and also the enemy now what we're going to do is right here after checking the sprite direction we're going to say add push vector if any so if there is a push vector we're going to add it we'll say move delta is plus equal to push direction now push direction comes in directly from the fighter so fighter knows if we have a push direction and and that's really all we need to do now uh push direction is going to be set once but we never reduce it which means that um if we get hit once we're going to start flying in a direction forever let's actually give it a try see if it actually does that um i'm going to go here i'll push the npc away and he's being pushed in that direction forever we're of course missing some kind of mechanic in here where that push vector needs to be reduced every single frame so we'll go back again in the mover and we'll reduce the push force every frame based off the recovery speed so this is why we do have the recovery um the push recovery speed on both the enemy and the players so we have it in the fighter i think we're going to say push direction is going to be equal to a vector3 dot lerp we derp in between the position sorry the direction we're going with our push and also vector three to zero and hopefully eventually we can achieve vector3 at zero so push recovery speed let's give this a try now say we go here he's going to run it into us and then be pushed by the sword and he barely got push but as you can tell he got pushed a little bit let's actually change the values so my sword has a bigger push force maybe three or even four and let's see my player has a push recovery of 0.2 now the enemy his hitbox needs damage so let's go here put one push for us let's put that on say zero point or maybe two i don't know how much is enough we'll actually try it out until it works okay so i do i do get push as you can tell like gently push at the moment we might need more than that so bigger numbers here but we do get push and that is some good feedback so what if we go back in the enemy and actually give it some proper values at the top here actually the enemy hitbox so damage could be equal to 1 by default and push force it could be equal to something like maybe five could be good i'm really wondering if five is enough and we can actually tone down our recovery speed as well on the player so maybe 0.1 this is going to cause us to slide a little bit more than what we were sliding before let's try this it's really hard not to hit the actual enemy because the sword is always in front so what if we actually disable the sword for a moment yeah we do get push so we get push fairly good and we can always come back like extremely fast because we have some push recovery speed um and of course if we just tone that down even more like 0.02 it's going to be harder and harder to come back you're going to slide for a long time which is not really what we want this looks really awful so let's go and put that back on one what we'll want to change if we want to be pushed further is simply the push force so what if the enemy has a push force of 10 okay that is obviously a little bit too much by default we put it on five and that is again a little bit too much maybe if we change our push recovery speed back to 0.2 this does make a little bit more sense you know but we're still jumping around a little bit too much so i'm thinking about reducing the hitbox to say three three could be good and the player recovery could be at 0.2 those value you can play around as much as you want until you have something that feels really good okay so at this point we pretty much completed these two tasks there is one thing that i haven't done just yet and that will actually tackle in the next section it's gonna be how to use the animator to make this thing swing right now we have a weapon in our hand but it never swings so it just stands in front of us and it hits the enemy because it's it's just there but in the next section we are going to actually learn how to use the animator in unity to make sure that this thing swings alright guys thank you so much for watching and i will be catching you in the next section welcome to a new section in this one we are going to learn more about the animator and also the animation window in unity if it is your first time using a keyframe kind of system you're going to experience something that is quite cool something we use in video editing something we use in animation and a bunch of other places and i think that's going to be quite interesting if you haven't ever used a software like that before or some kind of system that use keyframes so we're going to go ahead and i'm just going to put that in my script folder for some reason it was out and we're going to go in the artwork folder now under the artwork folder there's this folder called animation so what we're going to do today is we're going to create a swing animation for the sword we're going to be using the animator and we're also going to be using custom animation that we'll make by hand so we're going to go under player then weapon and we're going to go in add component add a component type of animator and now we have to create a new animator so we'll go beneath animation right click create animator controller that's the name of it and we'll call it weapon let's go back on weapon make sure that the controller field over here is our brand new weapon animator controller and then we can start animating this thing so let's double click on the sword this is going to zoom in your view and you'll see it in the scene view i'll just make sure to make a lot of room for this one then i will go under window and find the animation window or you could hit control and six we now have the animation window somewhere it is currently on my second screen but it should actually pop up in yours if you only have one monitor and you can actually hanker it somewhere i put mine just beneath the scene view okay so right now while we have the weapon selected you're going to see that it's going to ask you if you don't have the weapons selected it's going to ask you to create a animator and a animation clip if you go under weapon you're going to see that it doesn't ask you to create the animator because we already have one so weapon is our animator controller now we're going to create a animation clip let's set create call this one weapon underscore swing and we're going to drag and drop it in our animation folder ok so that is the very first step the second step is gonna be to keyframe this thing now this is where you're going to get creative and create the animation for your sword uh remember we have a cooldown on our sword where it says we can only swing every half a second so we had a 0.5 f for the uh the cooldown time so we can only swing twice a second so i'll make my animation 30 seconds now what i will do is i will actually click on the recording sign as soon as you hit the recording sign whatever you do here whatever you do in the inspector is going to be as you can tell um put there in the animation window so you got to be really careful what you do once you click on that let me just revert it we are currently recording and i want to make sure that this is the beginning frame so this is where we start our very first animation i'm going to be putting a keyframe in here so let's hit add keyframe now i will be putting a keyframe in here so let's make sure that at the very beginning we save the position of this thing we save the scale and the rotation so we could do add property transform and just get them all or what i'd like to do is just slightly move them just like if i was replacing them uh slightly rotate then reset the rotation back to zero and you can also slightly scale this way once you modify that everything is going to be turning red and these field will now be keyframe alright so now before we go any further let's have a look at what exactly is this keyframe system we're talking about most if not all of the keyframe system they all use three different things first you need a timeline in this case we have a time in between zero and one second now we could zoom out as you can tell i can go up to 10 seconds i can go up to as many as many seconds as i want but we'll actually keep that in between 0 and 0.3 like we said because we have a cooldown of 0.5 now i'll be removing these two i don't know why they are here but we're going to go back to the default settings where we only have the initial keyframe so first we have the timeline second we have these over here on the left hand side so these are the properties we're going to change and now every single one of those property are going to have keyframes so first timeline second properties and then keyframe it is fairly simple way it is going to work like this so assuming that you have your timeline you decide that at 0.3 seconds you want the sword to be looking like this well since we're using the record mode right here it's quite simple all we have to do is move it while being here but what's really happening down here is that it creates a new keyframe for every single thing we saw and it just assigns a value match to a certain time so at 0.3 the sword has to look like this like no matter what happens the sword has to look like this now the really cool thing is that they'll do interpolation for us so in between these two points there's going to be a smooth transition the whole time so let's actually give it a try let's create a real animation we said to ourselves we only want 0.5 second of animation so that is it over here 0.3 what we're going to do is take all of those keyframe i will hit copy and then paste so whatever happens in here um you know it happens but then once the animation is over once the animation is done i want the sword to go back to its initial state so our animation has to fit within these keyframes so we'll do everything in here now in video game animation we want something that is very very fast you want something that is extremely responsive so once you press on the button you should be able to have the the the sword fully extended like a matter of few frames i'm gonna go with 0.5 frames i want to have a full extension of the sword at 0.5 now we're currently recording at the moment so we'll actually just move it in the scene view and it will be automatically giving us keyframes at the end here so the full extension could be something like that i'm just improvising a little bit and then it would retract over time we could actually move this a little bit towards the 10. and here it is so if we play this you're going to be seeing the animation now i'm going to do a little bit of modification because i'd like the sword to actually hit down here as well so i'll try and create something that goes a little bit beyond that so say over here and we'll just try really really hard to make this look good so i'll actually move that like this could be a lot better it does look weird though but the more we work on our animation the more we can make this look good but i will be keeping this like that for now as you can tell we cover most of the zone in front of us which is uh what i wanted in the first place if you just pop the collider you're going to be able to see which zone it covers exactly okay so now this is what happens when you swing your sword this is what happened visually the cool thing about animator and the animation in unity is that you can actually add more property that are not really something visual you can actually add more things that don't have anything to do with the visual let's actually give this a try so what we're going to do here is turn on the collider only when we're swimming the sword so you remember earlier when we were actually just uh going to the enemy over here and it was automatically hitting him we're going to disable that if you want to hit the enemy you need to have your swing and you need to you know deal damage to him when you press on spacebar not when you just walk up to him so here is what we're going to do we're going to hit the record button at the very beginning and say as soon as we're ready to enable the collider which could be like right at the beginning over here we're going to make sure you're on the record we're going to toggle off the box collider and then toggle it on again which is going to create a keyframe over here and it also create another keyframe at the beginning let's make sure we remove that one we do not want to have that one at all costs so at this point assume that the collider is off here it is going to be forced to be turned back on now once we're done with the full swing we're actually still while recording we're going to turn it off which means that if it is off here it's going to be forced to be enabled on that frame it stays enabled this whole time and then finally on the last frame it is going to turn off okay so let's turn off the recording and let's also turn off the box collider by default so there is no box collider here at the beginning but as soon as you click that keyframe you're then going to have one next thing we need to do is to create a idle state the idle state is going to make sure you're back on the normal settings so the settings you had prior to swinging and it is just some kind of safe thing to do because you know you already go back to the default setting at the end of this animation but we have to make sure um it is actually 100 sure because sometimes you might be cancelled in the middle of your animation uh by some other state we could be calling so let's create another animation over here we're going to click on weapon swing from the animation window and create a weapon idol and all we'll be doing in this weapon idol is a single frame now let's hit record i'm going to slightly move the weapon and then put it back exactly where it was uh rotation same thing or we could go down here you know like add rotation add scale and finally there's one more thing we enable and disable the box colliders let's make sure we disable that here and we leave it disabled okay so that should be our idle as you can tell we have weapon idle this is a position right here if we hit play you're going to be seeing it in the game all these fields that turn blue including this little check box over here they're all things are going to be affected by animation if you go back on swing same thing here they all turn blue because they're going to be affected by the animation now in the next lesson we're going to learn how to connect these animation to our code to actually call them once we need them welcome back to another lesson in this one we're simply going to learn how to connect our code to the animation we just created in the last lesson now it is fairly simple we're going to start by creating a graph in mechanim to do that we need to open up the make a name window there is two way to do it you can either go under window and go under animator which is going to open this up or you can simply double click on your animator which is weapon right here so that's our animator controller at this point you should be seeing your 2 animations sometimes they do pop up if you have done your animation in some kind of different fashion they might not even be there in the first place if you don't see them go ahead and right click create a new state for every single one of these right now we only have two and rename those state using the inspector at the top right this one would be weapon idle and we're going to make sure to connect the motion this is only a animation state it's not actually going to link to our weapon idle we have down here so we have to make sure we put the motion weapon idle in here now we're going to do the same exact thing for the weapon swing and also change the motion from here you're going to see a pretty pretty easy to understand graphic flow entry is as soon as the game start what happened when the game start well weapon idol is what happens when the game start now if this arrow is actually pointing towards swing like this make sure you right click on the proper state the proper one that should be executed when the game start and you're going to turn this into the default state okay now what happens at this point is that the sword enters this state and it just gets stuck in here because nothing can get him out as you can see there is no arrow pointing out there is no arrow pointing to anywhere really not even the exit now in our code what we could do is once your weapon is idled and only when your weapon is idle you're allowed to swing assuming that x condition is met and we can create those condition using parameter at the top here so make sure you go under parameter and then you have a empty list we can then create a list these are all basic um variable you can use variable types you can use the float you can use the hint a boolean in our case we're going to be using a trigger now um this trigger i will be calling it swing and i'll go over how to use a trigger in a second if you would be using a float it would be fairly simple you could say if that float is bigger than say 0.5 then you do this now this is really useful for say speed value what you can do is keep feeding the speed value to your animator and then your animator checks if the float value of speed is below 0.5 you can now walk if the speed value is above 0.5 then you should be running so the animator in here could be taking care of that logic now um there is a boolean as well it works just like in normal boolean and finally there is the trigger now the trigger is something you activate only once and it's not getting unactivated until it's being consumed so just like a boolean you turn it on but it never goes off until it gets consumed in this case what we're going to do is right click on weapon idle and create a transition now just like this if we were to play this what's going to happen is you're going to play the weapon idle animation and automatically after that one frame which is just one frame it is going to go to weapon swing let's actually give it a look sorry about that the game actually crashed for some reason so i'll just have the same exact layout work again um we had something like this and i've mentioned that if you start a game you're going to play weapon idol which is only one frame and then you'll move on to swing so let's give this a try as you can tell we played idle and then we're stuck in the loop with the weapon swing so we have to make sure we limit that to um we limit that to only when we press on the trigger now it's also important that you need to find a way to escape from the weapon swing so to exit the the weapon swing so we're going to right click on weapon swing and put a link back to idle and we're going to have this nice little uh side-by-side transition thing going on so this one is when you're going to weapon swing and then it just swings and once you're done it goes back to weapon idol if we play this you'll see that we'll be jumping from weapon idle to swing to idle to swing and that forever now how do we go and fix this we have to put a condition on one of these two transition of course we'll want to put the condition on this one over here because that's the one that goes from idle to swing and this condition can be found on the right hand side over here under condition we can simply click the plus sign and then you can meet as many condition as you want in our case we only have one parameter so they automatically put it on swing and if we don't trigger swing this is what happens it repeats idle forever and always now we're going to be triggering swing from our code but right now let's do it manually by clicking on this over here now there seems to be a problem over here when the animation actually plays for a second time and that is not because we've created about animation this is not because we have some extra keyframe it's because of the blending and how the whole animator worked together as you can see if you click on one of the transition you're going to be seeing some settings here with the blending time say you completely reduce that to zero percent or 50 in this case you're gonna be seeing that the transition is now fixed we can just do that like this and it is going to remove all the blending you could either go and do that you can also make sure there is no uh looping by clicking on your animation and turning off the loop time i'm currently under weapon swing and i just turn off the um the loop time as far as the weapon idle goes i'd like to leave that on loop um just in case for some reason one of the value of the sword gets corrupted and it has to put it back on the default location all right now if you want to make sure that you have the same exact animation as i do you're going to go under the transition in between swing and weapon idle and you're going to make sure to just collapse this back to zero and then put it back to uh like we just did a second ago now since i've done it um here it doesn't show up anymore but i just collapse everything here back to zero so turn it like that and move this all the way over here and then it disappear so we get a result that looks like this make sure it is both way actually just one way is fine but i just made it both way and it still looks good and we now have our player moving around and we still can't swing using the code but at least animation is now clean so this whole state machine in here even though it is a very very simple one it now works and we're now ready to go implement that in the code which is a very very easy task to do guys i'm going to go under the search and find my weapon.cs script we're then going to open up this weapon.cs and then we'll need to have a reference to the animator controller okay so if we had at the very top here we have the swing um part for the field so we're going to create a new private animator controller or just animator in this case that's the type in the code animator controller is just the name they gave it in the inspector and we're going to make sure to assign it during the start so we'll say anim is equal to get component type of animator just like this and now when we swing we're going to enable that trigger and the way we do this is by taking our reference in this case anim and we're going to say set trigger and then it's going to take either the id in int or the name of the trigger in our case we called it swing now note that you can do this for set float set boolean set int you have every parameters we saw you can also get those to see what is the state in um in the animator but this is how you transfer values to the actual animator so now what happens when we actually call swing after pressing on spacebar it is going to do the same exact operation as we've done manually so it's going to go here and click on the button but it'll of course it will do it in the code not manually through the window let's give this a try we're just walking around we're going to press on spacebar and we didn't even see it because it got consumed instantly and that's because there is no exit time assuming we did have exit time you're going to see it for a slight second here as you can tell it does pop up and then once the weapon.idle animation is completed and the whole blending is done then it does consume it but like we said we do not want an exit time we want something to be extremely fast and we can now go here and actually hit this guy nice so we just completed the very very little section about the animator and the animation window and now we have this animation of our little guy swimming his sword in front of him and if you guys realize we also made sure to turn off the collider of the weapon so right now we have no box collider on this thing so if we just walk here we get pushed away and the enemy suffers no damage so it's gonna be up to us to press on space r to make sure we can actually kill this enemy and uh he might need some slower movement speed but thus far we do have a working combat mechanic and is quite cool alright guys i will be catching you in the next section where we're going to start laying down a menu so some kind of ui that is going to let us upgrade the weapon going to let us see how much pesos we have going to let us see uh what is our current character skin and how also to change it so i'll be catching you guys in the next section welcome back to another section in this one we are going to start linking things together using a nice little menu that we'll be making using the new canvas system in unity it's not really that new it was introduced in 4.6 the reason i like to say that it's new is because you're going to be seeing some legacy ui objects around sometimes so you got to make sure you don't use them okay so we're going to start off by creating a new canvas we already have one canvas that is uh taking care of the floating text but for optimization purpose we'd like to have something else for what we're about to do i will be explaining in the future why you'd like to have two canvas differently and why it matters in terms of optimization at the moment all we need to know is how to create a new canvas so we're going to right click in the arrow key create a new ui and canvas let's make sure we rename that one for something like the uh the pause ui or let's find a better name for that so let's just call it menu there we go so let's go beneath menu and make sure we set all of these uh components properly the first one being canvas this one is already set properly it's going to be screen space overlay the second one is going to be the canvas scaler this one will want to make sure it's scaled with screen size just in case uh you ever decide to scale up your game make sure you you put the exact same resolution as what you're developing it currently we're developing in 800 by 600 so by default these are fine for me okay once this is completed we are going to create one big button um that is going to be acting as a background so i'm going to right click on menu ui button now this button i will be using it to actually exit the menu so once we pop our menu it's going to be there there's going to be a big black background with transparency and if you click on that background it's simply going to go back to the game so this is some kind of way to say if you click away from the menu you're going to be sent back in the game and we're going to call it background exit now i'm going to remove the source image for the sprite this way we can only have like a normal color as you can see right now it is white i'm also going to remove the text component then i will be making sure it takes the whole screen by going at the top left over here in the rag transform and making sure it scales on both axis i'm also going to hold shift so we have a different pivot point now if you have a look at your reg transform again you're going to be putting everything back on 0 and this is going to just take the shape of the whole screen of your whole canvas actually and we're gonna have that kind of result so this background is gonna be over the whole screen now to actually make it transparent we're going to change the color under image so let's put that on black and in term of alpha maybe put it on something like 50 or 150 something that's going to be hiding the background but not completely and then this will be our new button to exit as well as you can tell we do have the button component we're going to leave it here for now next up we can start adding the main piece of our ui so some kind of container that's going to have every single information we want to put in here i'll be right clicking in menu again create a new panel and this panel will make it something that is anchored in the center and has some fixed values in terms of width i'm going to be using something like 550 and height let's put that on say something like 300 i'm also going to give it a full black color with no alpha so i can have a solid background and that is going to be our container so i just renamed this to container alright so now at that point we just have to be creative we have three or four things we have to fit in here first one is the equipment so what type of weapon are you using second up is the character selection so just a um your sprite your character sprite and then a way to change it going either left or right third one would be um character information so how much help do you have what is your level and how much passes you have and then finally and i'll put that at the bottom of everything i'll just put an experience bar so i'll go ahead and i'll lay down what i just said so i create a new ui panel and the first one could be the equipment so put that on fixed size something that would be 200 and 300 in height i'll make sure to incur this on the very left side like this and also hold shift so my anchor point is also on the left side and i have this very first section over here this panel i will be calling it character equipment and i'll duplicate it the next one is going to be the character selection this one might be a little bit smaller let's make that 150 and i would just be putting it in the middle with an anchor in the middle so holding shift clicking in the middle not holding shift and then putting the value back on zero so we have something like this going on now let's name this one character selection and i'm going to duplicate equipment once more call this one character information and just change the anchor side from left to right this way we have something like this going on so we have three section on the left side we'll be putting the weapon in the middle the character selection and the character sprite and on the right hand side some more information such as how much health do you have what is your level and how much pesos and finally there's going to be one more thing is going to be the experience bar now the experience bar i will be creating a uh a panel again call it experience bar and i'll actually be playing around with um i'm not quite sure here let's actually do something like 550 so the whole size of this and about 50 in height and i'll be putting it at the bottom over here now uh what we could do is give it a full background with say some kind of purple color like this full alpha and on top of it is going to be another bar uh with a brighter color so we're pretty much done with the skeleton of our menu in the next lesson we are going to actually create some kind of animation around this so we can pop the menu and also hide the menu when we want welcome back to another lesson in the last one we created our skeleton for the menu in this one we're going to create some kind of animation so when the menu is on you see this and when it's off you just don't see it anymore now to do that we're going to need some triggers the first trigger we'll be using is a button on the screen so we'll have to create another canvas create a button and one once you actually click on that button you can then uh see the menu and then once you actually want to get rid of the menu all you have to do is click on another button to turn it off in this case is going to be the big black transparent box around the menu okay so let's get right into it it should be fairly fairly simple the first thing i'm going to do before anything else is to head over to the atlas and just crop myself a button now there ain't much in this atlas that can be used as a button for ui so what i decided to do is just grab this one chest that i haven't been using and turn that into a button so again making sure this is 16 per 16 i'm gonna call this menu underscore zero hit reply and then i will be creating a new canvas once more and this is like a like i mentioned in the past this is for optimization purpose i'm going to create a new canvas i'll call this one hud for heads-up display and we'll create a button at the very bottom left of the screen so i'll be anchoring this bottom left also holding shift and let's make that something uh only 16 per 16 at the moment and we'll just scale it up to see how good it can look in the game i'll be removing the text component and i'll be changing the sprite to our menu underscore zero all right here it is let's actually move the position x to something maybe like 10 so we'll have an opposite of 10 pixel in x and also 10 in y now in terms of scale let's actually try something like 64 by 64. if we go around and we play the game with this i think this menu is quite good looking it just stands here and if we press on it it's going to open up the menu so i'm going to be leaving it like that and it will make sure to actually connect this action to the opening of the menu now what i will be doing this time is a little bit different from what we're used to do so what we're going to be doing here is we're going to hook up the the button over here the button action will be hooking it up directly to the animator so this way we actually skip one step and that step was to create a public function in any script really and reference the button to go on that function instead we're going to be manually changing or manually activating a trigger directly in some kind of animator now we don't actually have that animator just yet so we'll have to go under menu and right here at the top level also on the menu i will be adding a animator just like we've done earlier we're going to right click on animation create a animation controller and that is going to be the menu by itself like that then i will be clicking on menu assigning that to the controller and then we will be creating some animation around that menu so when it's off we have a certain state and when it's on we have another state okay now we have our animator as you can tell if we open it it looks like this what we're missing is of course the states so we're going to need some state and those state needs to be based off animation so we need to create animation let's click on our menu open up the animation window and we'll be just dragging it in here and we'll start creating those animations the first one i'll be creating is menu underscore hidden and i'll just put it in the folder the second one i'll be creating is of course menu showing now menu showing is pretty much this state we see right here on the screen so that would be pretty much our state once the menu is showing we so all we have to do at this point is simply go here and uh start recording make sure you have your menu selected so we want to be saving the container position when it's not showing it is going to be somewhere say here at the top when it is showing we want it to be on zero position y so i'll just be moving it around as you can tell now the position is zero in y um something else i'd like to animate is also the alpha of the background over here so what i'll be doing let's turn off the recording i'm going to go back on menu add a canvas group and canvas group is something that's going to allow you to modify the alpha as gentel and also modify the interact ability and also if it rocks raycast or not so we're going to go back in the menu showing click on record and with showing we are going to modify the alpha make sure it is on one and also modify interactable even though we want it to be interactable we have to toggle it off and then on again so it shows up down here and it's actually being considered a a part of the animation okay now we're going to go back turn off the recording and then go on hidden once it is hidden let's put that on recording we're going to make sure that the canvas group has an alpha of zero so we don't actually see anything we're also going to make sure that it is not interactable and the block recast is not on so uh you can actually press this button down here if you didn't turn that off you would not be able to press the button because technically you would still be pressing on the background exit okay and what else we're also going to need and for the sake of this i'll be putting back back on one but we're also going to need to animate this container and put it somewhere say 400 or 450. okay let's go back here put that on zero and these are the difference in between hidden and showing they are quite easy to see now the animation in between them the blending in between them is going to be happening uh in between the states of mechanism so in between the uh these states over here and we're not really able to play anything right now to see how it's going to look like so we'll just have to implement it and then tweak it if we need to okay so we have our menu hidden and our menu showing when the game starts we of course want this to be on menu hidden so you don't want to be seeing the menu as soon as the game starts and then what i'll be doing is i will be creating transition from hidden to showing and showing to hidden we will now need some conditions and those condition could be based off a single boolean it could be based off trigger i like to do triggers i'll be using triggers one of them is going to be called show and the other one is going to be called hide now we'll go from hidden to showing only if the trigger show is there and from showing to hidden only if the trigger height is there okay now um all we have to do at this point is really just make sure we can hook this with our buttons and we should now be good to go so let's give this a try by going under background exit and there should be your button under background exit you're going to link menu which is the container of your animator and you'll find the animator which is right here will do a set trigger string and you're going to say that is the hide trigger so you're going to try and call directly this thing to happen through a button and not through a public function and then we have the other button which is under hud and that's the menu button which i forgot to rename and we'll be putting the same exact thing so let's go back on menu take its animator and do a set trigger this time it's going to be show all right so if we play this right now we're gonna have this kind of behavior going on so at the beginning it isn't hidden and if we press on this button the menu comes down and if we press anywhere at this point it should go back up and that's really it for our menu so we just did the animator for that menu we can still move in the background that's fine by me if we did not want to move we could also set a time scale to zero but in this case i think i'm pretty happy with the result of this now there is one last thing that i don't really like and sometimes you can tell there is some kind of slight delay when i click i have to wait and that can be simply fixed by removing the exit time so let's go under the transition and remove the has exit time on both of these now we can go ahead and play this have instant responses so when we click it shows up when we click away it goes away and that is it for the menu animation in the next view lesson we are going to fill in those blank squares so we can have some good data in there alright i will be catching you there welcome back to another lesson in this one we will start filling in this menu skeleton we had in the previous episode we're going to start by opening it up and under menu we'll start with the character equipment so this one i want it to be quite simple i just want to be able to display the um the current sprite of the weapon and then a number below it with a button and if you click that number you spend x amount of peso and you upgrade your weapon so quite simple stuff of course if you want more information you can always decorate that as much as you want mine's gonna be quite simple i'll be going under ui and i will be putting a simple image like this now that image um we could give it a dimension of say a hundred by a hundred and fifty that would be like the background where the sword lies and i could actually say yeah it's gonna be in the center position 15 y and of course those values something you could definitely just modify on your own i'm like there's no it doesn't matter what kind of value you put in here whatever is going to look good for you is is what matters this one's going to be called the weapon container and beneath it i will have another ui another image this time and that image is gonna be my weapon sprite um so in this case i will be finding the very first weapon we have i'll make sure to actually set the native size as well and then i'll scale up from there so i can have the the proper aspect ratio and then i'll just scale this up if we need to and obviously in this case we need to maybe go for something that is five times bigger than what we had and this will fill the whole container so maybe a little bit smaller four four and four okay so we have the weapon container we have um the image needed i'll just call this one weapon sprite and let's also create a button so ui button and we will call it upgrade button and i just realized i started putting space in between let's not do that because we have not been doing that since the beginning i'll just go ahead and correct this okay put the button beneath everything i'll make sure to anchor that below the size of this thing could be well actually i'd like this to be the same exact size as the the background so the weapon container i want this to fit the weapon container at all time on the x-axis so i'll go back in here make sure i click on stretch horizontally and then i just put everything on zero as far as the height goes let's go with a something like 50 and we'll just reduce that from position so maybe minus 50 in the position as well and of course if you have some nice image you can put as a background do that in my case i unfortunately don't so i might go for something like a gray oh i'm on the weapon right now i want to be on the weapon container then i'll put that on some some kind of gray and i'll just reduce the alpha maybe something like this but if you do have like proper buttons proper background go ahead and implement that it's gonna look so much better and you'll be more motivated to work on this okay in terms of the text i'll put that as a number for now now as far as the text goes i'll input a number because in the end what i want to have right here is the amount of peso you have to pay to upgrade your weapon so later on we're also going to go get a new font so i don't want to work too much on the text just yet but eventually we're gonna have a new font so the font size is gonna change so i put that on 30 for now it's a little bit too big but like i mentioned it will change when we change font as well okay so that would be it for the character equipment all right so next up we have the character selection in here we will need an image that's going to be the characters right this one let's make sure it actually fits the same exact um aspect ratio so something like 15 20 could be close enough if you want to have the perfect aspect ratio just go ahead take one of your player and do set as negative size this way is going to give you the proper respite ratio and you can just start scaling up from there so let's find out what could be good looking we don't want to go too too big with that simply because it it's too small uh you know it's really small in this case that's 16 per 16 so if we go very very big it is not going to look so good as you can tell so keep it small keep it simple let's uh let's actually use this one that looks fine uh maybe bump it a little bit higher in the y-axis so i was thinking about 10 or 20 or 30 because we want to leave some space at the bottom for some buttons so these button are going to be coming in right now we have a new ui button and that is still inside of the character selection i'll call this one left arrow and we'll give it a shape we'll remove the the text inside of it we'll just take this one shape uh make sure it is say i'm going 16 per 16 again way too small what about 50 by 50 that could work if we make it um if we make it take the proper place in the screen so what if we do minus 25 we're going to go on this side and in terms of y let's do minus 40. maybe something could work something like this um might push a little bit further on the left hand side to the right arrow this one that's about to come up can have some spacing in between like mentioned this lesson is all about you and what you want your ui to look like i'm giving you the one i'm using right here of course you can copy it pixel per pixel but where's the phone in that just be a little bit creative and uh you know try to just move things around i like to compare those prototype ui to my room i like to just switch things around most of the time so um i don't really focus on you know the final aspect of it the final design of it just yet because we'll have to give it a try we'll have to try it in the game to see if it feels good or not so while you're just prototyping while you're just laying down the skeleton of the ui i don't think you need to spend so much time just put things where you know somewhere you can see it and somewhere where it can make sense and then while you're playing you'll understand where it would make more sense and where your cursor is at certain part of the time like oh upgrading here might not be the best place maybe you want to put it really really close to this button so you can do a quick upgrade and you see where i'm going i mean it really depends so you'll have to try out your game before you decide on your final uid which is also why uh being a ux guy is is a job you can have a job where all you have to do is create ui for the whole day so under character information let's keep on going under character information i'll go and create some texts the first text is going to be the held label and i'll call this label because i will be uh adding something beneath it so that's like the title and beneath that's gonna be the paragraph so this one health in all caps i'll make that centered i'll give it say a well white color would be good in this case so a big white color and like i have mentioned don't worry so much about the scaling of this because it's going to change once we import a new font what does matter is that we're going to make this stretch on both axis i'll go with say minus 50 and i'll put everything back on zero maybe a height of 50 as well okay right and beneath that is going to be another text object i'll just duplicate this one and that's gonna be the health so we have the health label and then just beneath that we're gonna have the actual information this one i could put it on um -25 like it is right now but i want to make it so it's -25 from the parent how do i go about doing this okay so i just did it by uh going back in this menu over here and holding shift to set my anchor point at the top as well now i can go here and say -25 and in this case the font is going to be a little bit smaller so let's try 15 um and some you know some place older text as well something like this cool next up copy this we did once let's actually move down to say minus 100 maybe 125 and once more this time minus 200 cool we're going to change the second help label for level label and finally pesos label as you probably guessed we're going to change that for level that one for pezos and change the text inside of it as well level could be 5 and pesos would be 75 we can also play with the color of it so pesos could be yellow and level could be purple or you know that color um definitely doesn't look that good right now so what we're going to do make sure it fits put it around here and we now have the art or at least a visual aspect of our menu the right hand side of here the one we just did this is going to change without user input so you play the game you collect some pesos this is going to change you get hit you lose health this one in the middle is going to be the character selection so this one we do have an input the left button and the right button and finally on the left hand side we've got the sword of course this one does have an input um you click on this button if you do have the amount of pesos required you are going to update or sorry upgrade your weapon oh and one thing i almost forgot is the experience bar so we're gonna go under the experience bar create another ui image of the same exact size to do that i can either input it manually or make it stretch on both axis then put everything back on zero so this is going to give me a um an overlay of everything we had and we'll just call this one progress what i will be doing is through code i will be changing the scale and as you can tell when we do change the scale it's going to shrink but now we have to make sure it shrinks from the proper position so what i'll be doing with this proper size here when everything is put back on zero i'll go and click here put the anchor on the bottom left so i'm holding shift or you can just put it on the left right here and then it is going to return to a normal object that does not stretch and the width and the height is going to be set and we have this new anchor point which means if we reduce this or if we increase it it's going to play just like a progress bar so i will be leaving that to full and um changing the color of course so i'll just be picking a brighter shade of this color something like this all right now one more thing i'd like to put on this experience bar and it's to actually display the amount of experience you have and how much experience you need to level up simple thing we just create a new ui text we make sure it is um stretching on both axis this one is fine anchored in the middle alignment in the middle bigger font maybe 30 and then we just type in our text our default text will be of course modifying all of that as we see fit okay well that is all we needed to do to put all the art in here uh we're pretty much ready to start implementing the mechanic behind those so i will be doing that in the next lesson guys i will see you there welcome back guys in this lesson we are going to start implementing the code behind this piece of menu so let's click on the menu go under the add component and we're going to call this character menu or whatever you feel like calling it my case character menu i will be opening it up in my favorite editor cleaning it up like i always do and then we're going to get started so we're going to need a lot of field in here we're going to be playing with a lot of different variables let's start with the the text fields so we're going to start declaring a public text level text if you have not realized we're going to need to implement unity engine.ui so if it is not done go ahead and use unityengine.ui and then we'll declare them on the same on the same line so level text we're gonna need hit point text we're going to need pezos text we're gonna need the upgraded cos specs and finding the xp text all of those are required because we'll be updating uh what's inside of the menu and all of those are dynamic values that we need to update okay um next we're going to need some logic field and those are for the sprites for the character sprites and also the weapon sprite so let's go and start declaring a private int current character selection that's your selection in backs so if we have zero we're looking at the player underscore zero if we have one we're looking at the player underscore one we're gonna need a public image character selection sprite and another public image you can declare it on the same line if you want weapon sprite and finally a public rec transform for the xp bar i mentioned in the last lesson that we're only going to be using the local scale to actually do the progress bar so this is why i'm using a reg transform over here all of these are public so we'll have to go assign them manually as soon as we are ready okay but before we do that let's start declaring a couple of things so a couple of functions we will be using first one could be um i'm not quite sure we have a couple of things in here we could do the character selection first so let's go and do that we're going to need a public void on arrow click this is going to be the function um that the button the two buttons are going to call now both button are going to be calling the same function whether it is right or left is going to be determined by this boolean we're going to pass in so i called it boolean right if we are clicking on the right arrow that brings going to be true and if we're clicking on the left one it is going to be false so this is how i know which button we're going to click now if we are pressing the right arrow well we have to do something like this so current selection plus plus we're incrementing that by one and if we went too far away in the array so if there is no more character um after the current selection we'll have to do if current character selection is equal to game manager.instance count so if we reach that point that means we have to go back to zero so current character selection is equal to zero and then on selection change which is a function that we will be declaring right after that okay now if we're going right we do the exact same thing but you know the other way around so i'll just be copying this we'll say current character selection minus minus if the current character selection is smaller than zero that means we went to minus one and that is not valid for your array we're going to say it's equal to game manager instance player sprites count minus one because we are zero base okay so in these two these two are quite simple algae written at the end of them i call the function call on selection change so if we did manage to change the character sprite or actually just the current character index then we're going to be calling this function so private board on selection change and then in here we can apply um the different sprite which should be quite easy all we have to do take that selection sprite we declare at the top say the sprite is equal to game manager instance player sprites add the index current character selection and that's it that's all we have to do all right so that was it for the character selection next up we could have the weapon upgrade so weapon upgrade and it's also going to be button so we'll do public void on click upgrade or if we just followed that that way i was scaling thing earlier we'll do on upgrade click instead okay now inside of on upgrade click we are going to need a reference to the weapon which is not something the menu has so i'll be leaving this empty for now but we'll have to go back and get a reference to weapon and the way i think we're going to be doing this is by using game manager so the game manager is going to try and update the weapon instead and finally we need some text just to update the character information so that is all the text field you saw at the top here we need to upgrade all of that so let's go ahead and do it we're going to declare a function call it public void update menu and inside of update menu and then with the update menu we run into the same kind of problem we ran into with the on upgrade click we are missing some information in the game manager to just complete these properly so what we'll do is um we're going to fill in what we can but then we'll have to go in the game manager implement the weapon in there properly and then come back here so uh let's do say we have the meta we have the weapon which we can't do at the moment so let's leave that empty in terms of meta we can do hit point text that text is gonna equal to game manager instance player hit point to string and then we can also do the puzzle so pesos.txt is equal to game manager instance um pesos to string and that would be it we cannot do the level just yet simply because there is no mechanic created around the level so the experience mechanic is not created just yet so we'll just leave that empty let's do level text dot text and we'll leave that to not implemented okay so something like this we'll have to come back here of course um weapon sprite is also the same exact thing so we'll do weapon sprite since we're here i'm going to write down the line but you know we can't really put the proper thing in here so there's going to be a bug i will just say weapon sprite add the index 0 same thing goes for the text beneath the weapon so the upgrade cost text we can say dot text not implemented and finally there is the xp bar so xp bar um this one also not implemented we don't have the xp mechanic just yet so let's go ahead and say xp text oops that text is gonna equal to not implemented in all caps and we can mess around with the local scale so we could say xp bar that local scale is equal to oops again i'm tapping too fast is equal to a new vector 3. let's say 0.5 0 0 so it's going to be halfway um completed okay now we have the update menu we'd like to hook this up every time we open the menu so every time we open the menu through the button it would be nice if we have a nice refresh of all that data so refresh of all this metadata we have here refresh of the weapon refresh of well pretty much everything so let's go ahead and add that as well to our little button call over here so remember that button in the hud the menu button hiding behind everything right now we're going to add a new function to it right now it's only setting the trigger of an animator we're going to hit the plus sign choose our menu because that's where our character script is character menu is and we'll go ahead put our function here so character menu update menu before we test this out we have to assign the value so back on the menu let's expand it completely so including these down here and we're going to set everything manually so let's go ahead and find the level text here it is the hit point text pesotex the upgrade cost text that is on the weapons upgrade button at the top here the experience text could be on the experience bar character selection um that is our character sprite so did i type that properly i don't think so character selection sprite okay so it is typed properly we just don't see the whole text because it's too it's too big here it is um for this we're going to need this little boy in the center so let's take the character sprite put him here weapon sprite just goes below and finally the progress goes in here let's actually try and play this game right now we just collected a total of 30 pesos and they have not been updated because argument is out of range what is wrong exactly let's find out what's wrong okay so it turns out we get an argument out of range simply because we have um this thing over here when we update the weapon we say the index zero but we don't have a weapon sprite array yet i mean it's not it's not filled at the moment so let's go back on the game manager and put something in the weapons right actually let's put them all since we're here how many weapons do we have i think we have six i might be mistaken let's type in a weapon and we have a total of seven including zero so click on this one first let's go up to seven and just fill in that array with our shiny little weapon and then five and then we need a total of seven for the golden sword when we play the game at the moment we should not have any problem let's go and open this so not implemented not implemented health is a 10 which is true the amount of pesos um is still zero because we never went and implemented that let's actually do that as well we're gonna we're gonna start connecting things together right now i'm gonna go right into the chess dot cs and where we say this we're gonna also say game manager dot instance pesos plus equal bezos amount so that's all we needed to complete this we should have done that earlier but my bad on this okay so we are back in the game pezos is equal to zero collect 25 and it's now 25. so our text works um a couple of things are not implemented so we have to go ahead and connect everything together now what we will be doing in the next few lesson actually in the next lesson is make sure the weapon works 100 so we're gonna have the upgrade on the weapon we're going to have the swap of sprites but we're not going to tackle the xp just yet we're going to take care of everything weapon related and then we'll move on to the character sprite and once we're done we are going to move on to the experience so stay tuned for the next lesson i will see you there welcome back to another lesson in this one we will be taking care of doing everything we need for the weapon so to get started most of our work is gonna be done in the game manager today so we're going to double click on it open it up and this is where we're going to unlock the true potential of our weapon so remember in the reference over here we've created this temporary field well it is no longer temporary we are going to create a public weapon called the weapon and in here we have everything we need already so we did we did think about the weapon level we did think about these stats over here we have to change everything is pretty much done in the weapon most of the work is going to be done directly in the game manager alright so let's do it we're going to go down here in the section where we create all of our function maybe go down uh in between the floating text and also the the save state and just create something for the upgrade weapon we'll do a public boolean called try upgrade weapon and this one is all gonna make sense uh as soon as we complete this whole flow so what's going to happen is the menu is going to call this function so it's going to call try upgrade weapon simply using the game manager instance dot drag upgrade weapon and if this one returns false then we're not going to change anything on the menu if it returns through it means we completed the upgrade and then we're going to change the sprite in the menu we're going to apply um the new sprite in the game and you know it's just going to change everything there but only if this returns true so the menu right here the the game manager is the one that knows whether it's going to succeed or not because our values are here our pesos are here the the upgrade costs are all in the game manager so it did make sense we put it here let's start with a very simple call is the weapon max level right now so are we maxed and the way we're going to know if we're maxed or not is simply by counting using um the weapon prices dot count so if weapon prices account is smaller or equal to our weapon dot weapon level so if that's the same or smaller it means we are already maxed out and let's actually return false we have to return a boolean almost forgot so we're going to return false right away so no way we can upgrade further than that now if we can go a little bit further we're going to check with the amount of pesos we have so if bezos is bigger or equal to weapon prices at weapon weapon level so we're using the weapon level to know exactly where uh to look at in the weapon price array weapon zero is going to cost x amount um from the weapon price array and then we just keep going in parallel those two area are going to increment in parallel so uh when you upgrade your weapon the price also upgrade if we do manage to do that let's reduce the amount of pesos so let's deduce the amount of pesos so price is minus equal to weapon price add the index we just talked about and then we'll actually try to upgrade that weapon i think we did have that in the no we didn't have that in the weapon so weapons gonna need a new function called upgrade weapon something like that very simple which will basically just um do what we said so it's going to change the sprite is going to increment the stats of that sword okay now there is one more problem left with this algorithm with this function actually is the fact that we might not actually return anything here we have the if statement but here we also have a if statement so in case none of these two were called so in case uh we are not max level but we don't have enough bezos we're going to return false simply okay now that should be everything we needed to do in the game manager we're going to hop on the the weapon class because we have encoded this upgrade weapon function so let's go in there i'm going to navigate the weapon press f12 then on the class name press f12 and we're going to scroll down at the very bottom let's declare a public function public void called upgrade weapon and in this one we'll do a simple weapon level plus plus also change the sprite so sprite renderer dot sprite is going to be equal to game manager instance weapon sprites at the index weapon level and this way we're able to change the real physical weapon in the game now um we still have to change the one in the menu because once we upgrade it every time we open the menu it's going to be uh verified but if we are already in the menu and then we upgrade we want it to change there as well so we want them to change it um pretty much live so uh there is one more thing we'll have to do in here it's going to be to change the stats we'll come back in a second to this but let's go quickly in the character menu where we were in the last episode and we're going to go up here on the on upgrade click the way if game manager instance try upgrade weapon so if that succeed if we get it through then only then we're going to update menu if we click on the button and there was no upgrade we are simply not going to update the menu and that should be it so we pretty much completed that flow um we're going to need one more thing like i mentioned a second ago we're going to need to upgrade the weapon stats and i just realized we don't have an array for that we don't have some kind of structure with the new um the new information just like we've done for the weapon price we could go ahead and create another array uh say in the game manager that could take care of that so we can either create it there or we can create it directly on the weapon in this case it's really up to you i feel it would be a little bit cleaner to do it directly on the weapon so i'll go ahead open up my weapon and at the top here where the damage structure is we will actually turn that into an array that makes sense right public int array damage point and we have a total of if i remember we have a total of seven so let's make that one two three four five six seven i know that is extremely creative for the amount of of damage we will be doing um same thing with push force we can start at two then go up to 2.2 2.5 this one's a big jump so 3 maybe 3.2 and 3.6 so how many do we have one two three four five six and finally one add four something like this could work uh let's make that a public float array and it should work now we have to change what we had earlier so on our uncollide function which is on the weapon instead of using the damage point like we were using earlier we're going to be using damage point at the index weapon level same thing for the push force and just like this we can make that work now i've assigned some values directly in the code here but since we made them public they're also going to be visible through the inspector right here oh they were actually uh not a sign that is quite weird maybe that's because they were public before what if i do a reset yeah if i do a reset it's going to take the value directly from um from the script so i did a reset and now my values are all in here and if i need to tweak them i can do that quite fast okay now to wrap up the weapon we have to hook up our menu to our actual logic should be quite simple so let's do that super fast we're going to go under the menu let's go under the character equipment upgrade button an upgrade button is going to be put on um i think it was under menu right character menu on upgrade click here it is if i press the game if i press play on the game and i go on my game manager while it's running i'm going to give myself some pesos so let's see where is my game manager oh it's on the uh don't destroy on hood now i'm going to give myself a hundred pesos in this case open this up click on this and we get a no reference exception so what is this from the weapon price array has not been filled in and that's completely true again i forgot to do that at one point i should have done that before so back on the game manager um weapon prices we have a seven weapon let's go ahead and make that seven prices as well actually i lied we only need six prizes because we already own the first weapon okay now let's say the first weapon's going to be something like 35 second could be a hundred um that's going to take a lot of grinding actually let me go bomb those down maybe go with 30 70 then up to 130 and then maybe 200 at that point we can go in crazy number and finally 400 for the last one okay let's give this a try we're going to go right into the game collect some puzzle we should have enough for the first weapon upgrade so let's click here click there and we have a no reference again what is that problem oh so the weapon price is actually failed we just don't have a reference to weapons so something i forgot again let's head back into the game manager and over here down there there is no weapon let's actually drag our weapon here making sure everything is correct we're going to collect those pesos again and this time it's going to work i hope so we did lose the peso this was not changed over here did we have a new sword we do have a new sword so the only place where it did not work is in the menu so the menu i remember we actually did not implement it just yet we're gonna have to go back and go in the update menu which is down here and change this to weapon level so game manager instance weapon weapon level now for real this time this should actually work we're collecting everything and it did change over here we did lose in the amount of pesos and we have our new sword does this one do two damage let's try it out yep it does do two damages and we were able to to hit this little guy because he has three hp okay so that is fairly cool there is one more problem that we'll have to address eventually we're pretty much done with the weapon in the ui thus far but there is one problem where um this is not actually being saved in the save state so again we're going to go fix it right now so we don't leave it hanging and in the same state that is inside of the game manager so in our save state we do have the weapon level we just have to change zero for an actual value so weapon weapon level two string that is fine for our save state let's go in the load state now and here we have changed the weapon level so we'll do weapon weapon level is equal to int that parse and that would be data at the index three if i can remember correctly yep data in the index free let's go ahead and test it out we're going to upgrade our weapon it is now the rusty sword let's walk through this so we can save the state and then this one doesn't load up things because we have not copied our scene thus far but we're going to go back in the main scene and see if we have the proper weapon now obviously we do not have the proper weapon in our hand but if we have a look in um in the menu we have the proper weapon and if we go under the game manager you're going to see that our weapon weapon level should be one so this is fine the logic is working we just don't have the right sprite so let's go down back in our code so right here this is not enough this is only going to set the level value and we wanted something else we want something that sets the value and also changes sprite there is two way to go about this what we can do is create a function inside of weapon to be clean we can create a function inside of weapon or we could go and turn this one into a public manually change it from the game manager so we can go back here say okay we just want to duct tape this so let's do weapon sprite render and then we say sequel to the weapon sprite array but instead what we're going to do is head back in the weapon turn that back into private and we're going to create a public function public void set weapon level and we'll be taking it in here so level it's going to do the same exact thing as upgrade weapon and we don't need to change that anymore but instead of doing a plus plus is going to say is equal to level and we will now be calling this from our game manager instead of calling a change weapon level actually instead of changing manually the weapon level so it's going to look something like this and everything should work for real this time so we run into a null reference exception and that is because our sprite renderer at that time is not actually set so we don't have a sprite render simply because the game manager when it runs it does a load state in the awake i believe so that happens fairly early and by that time if we go on our weapon we don't have a spread error just yet because this one's private we set it in the start as you can see they don't have the time to um have this working so what we can do instead is we can reorder things so the sprite renderer would be done in a wake so private void awake remember wake is being called before we could do that and that would fix the problem so if we go and play this we should not have any more error in the console as you can tell it's here we have the proper weapon and it is it is just ready to be used now that's one way to do things the other way you could have done it is by making this a public thing the sprite renderer could be public and we just assign it through the inspector just pick which way you like the best i will be going with the inspector way you don't have to do that you can just put it in the awake and from there you'll be able to launch your game have the proper sword in your hand and defeat this little guy here oops so we still hit four two and for some reason he died there i'm not quite sure why we'll have to figure that out as well hi guys alright so we're pretty much done with the weapon uh again one final thing i i know i keep doing that one final thing but i keep forgetting we have to change the text right here because we did implement this we can't say it's not implemented anymore because it is let's go ahead and change that text to the proper amount of bezels you have to pay i'll be opening up the character menu and where it says not implemented over here we are going to create some kind of formula we are going to create a very very small algorithm because there is two options here the weapon might be max level and we have to change that to something like max like this or we can just you know put the real amount of places you need to pay i'll start with the if statement if game manager that instance the weapon weapon level if the weapon level is equal to gamemanager.instanceweaponprices.count then it is the max in that case else upgrade cost text dot text is going to be equal to game manager instance weapon prices and that's going to be at the index game manager instance weapon weapon level make sure you cast all of this into a string by doing a two string and that is it so that's going to write the amount of pesos you need to pay and that is going to say max in case you are already capped hey let's go ahead and give this a try so we have to pay it all of 70 pesos right now to have this new sword let's go ahead and get this amount do we have enough now we have 55 uh let's cheat a little bit give ourselves 70. go in here upgrade that weapon we now have this brand new weapon this one costs 130 if you want it and uh should one shot this little guy yeah boy big damage alright guys i will see you in the next lesson where we will be doing the character selection welcome back to another lesson today we're going to be having a look at this character selection over here we're going to make it work and we're going to make sure that the sprite is indeed saved every time we quit the game or every time we change um which zone you are in right now so let's give it a look what we have at this moment we have the weapon working we have uh most of the thing working now these two buttons is something we have to code right we already coded a little bit of it if you guys remember let's open up the character menu we have the function that should be bound on the buttons and they were right here so on selection change and on arrow click are the two function we need on arrow click we have to bind this to our buttons so let's go ahead and do that should be quite quite fast so we're going to go in the menu head over to the character selection left arrow i'm going to hit the plus sign make sure i drag and drop the item that has character menu in it in this case that was menu and we'll find on arrow click now um this one takes an a boolean let's leave that one unchecked so false for the right arrow we do the exact same thing but this time we are going to check this boolean okay at that point we're going to give the game a try and we have a out of range exception all right so now what happens over here is that we have the on selection change and this one runs into a problem because current character selection could be equal to one and we don't have a sprite in here so in the game manager under the player sprite we have zero we have to make sure we actually put some character sprites in here and uh at the moment we only have two so let's actually add that put it on two and we're going to find the sprite first one was called player underscore zero and the second one was player underscore one having that done we're going to run the game now let's click as you can tell we have swapped in the menu but we did not swap in games we have to make sure we can also swap in the game okay now over here we have the on selection change and what we do in here is we make sure to change the sprite inside of the menu now we'd like to also change the sprite um in a game but we don't have any reference to that sprite so what we'll be doing is we'll let the player know that he needs to change his skin how do we get the player we are going to get it through the game manager so game azure instance player and we'll just do something like swap sprite with the index so current character selection swap sprite brand new function we're going to put right into players let's f12 on that player f12 on the type we are now in player.cs and we'll declare a public void swap sprite taking a end in parameter that's going to be the skin id and in here we're going to actually take our sprite renderer so get component sprite renderer sprite is going to be equal to game manager instance player sprites at the index skin id another way we could have done that is by keeping a reference to sprite this could be a little bit more optimal so we don't have to do a get component every time you know what let's actually do that i'm going to save a little bit of memory in here so private sprite renderer sprite renderer and in some kind of awake or start so protected override start we're going to do the initial thing so the initial base dot start but we also say sprite renderer is going to equal get component type of sprite renderer and here we go so we made it a little bit more optimal by adding a couple of line of code if we can avoid some get component call um the better it is okay let's go back in the game try this out we're currently rolling around with our initial skin if we go here and press you're going to see that a change in both the game sprite and also the menu sprite now if i exit and i have this saved we are going to run into a problem so what is this problem over here now the problem we're running into right here is something that we're going to put on the side for the rest of this section since we want to make sure everything is actually done with the menu then we're going to go on and fix this transition problem we have um the real issue right here is simply that since we have a game manager that purchases in between scene that game manager has some has some stuff over here to the player the weapon the floating text all of that is not being transferred properly over to the second scene as you can tell here they're all missing now which is what caused the null reference exception so for the remaining of this section we are going to stay inside of this scene and we are not going to exit until um everything is completed in here so we're going to need one more thing in the next lesson we are going to be having a look at the experience bar and how to turn this into some kind of leveling system as well so i will see you guys in the next lesson welcome back to another lesson in this one we will be creating some kind of leveling system that is going to be fairly simple um this way we're going to be able to fill the rest of our menu which is the experience bar at the bottom over here so we're going to start off by declaring um a couple of field in our xp table so how many levels do we like to have um i'm thinking about something like 10 we could go with 10 different level now the logic we're going to implement behind this xp table is the amount of xp you need on top of what you already have to go on to the next level so we can start with say 10 xp after getting or maybe even five so after getting five xp you're going to level up and then i could say here 10 which means to get up to level three you'd have to get first five xp and then another ten so 15 xp total to go to level 3 and we just keep raising that number as much as you want we can do um 17 in this case maybe 25 30 of course i want to make sure every time it gets a little bit harder and harder until the gap in between level is pretty much something like 120 okay so the last level so in between level 9 and 10 you're going to require an additional 820 xp on top of that okay so we have our xp table now what we're going to do is we're going to put the script in here because i'm tired of seeing it and we're going to open up our game manager create a couple of function maybe two function in here to get the current level of our player and also get the uh the experience to go to a certain level using these two functions we'll be able to wrap that around some kind of logic that would tell us what is our current level and how much xp we need to progress so i'll go right here in between the upgrade weapon and the save state i'll call that experience you could call it experience system and i will start with a public end get current level so this is going to return me an end of what is my current level very simple right for the algorithm behind this we are going to do a little bit of math we're going to start by declaring a int r that's going to be my return value and another int that i'll call add and you'll see what i do with this one i'll say as long as my experience is bigger or equal to add then we are going to add a level so r plus plus but before we do this let's make sure we add plus equal to the xp table r okay okay now let's go back and have a look at what this actually does we are going to start with an r of zero so our return value is currently zero we're at level zero and our add is also zero as long as experience is bigger or equal to zero then we're going to go ahead and add the first entry in our xp table because that's also index zero so add is going to be equal to five after this and then we can up the level so at this point we rerun the loop we know we're at least level one and um if your experience is bigger than five at this moment then we're gonna go ahead and do that once more so it's gonna be at least level two and so on when we're done we return r also let's have a check over here for if we are max level so if r is equal to xp table dot count then we're pretty much max level let's return our right away okay because the experience could go up and up and up and we don't want the xp table to be looked at if it's a if it's above the amount of entry it has so we don't want to have a out of range exception here let's actually test this out i will be putting that in some kind of random update simply gonna quickly create an update you don't have to do that if you don't want to i'll just say get current level um that could be it yep so again current level in a update my console should be spam with one at the moment or it's actually not because i don't think i saved properly oh i actually don't do a debug that's like my bad okay now that makes a little bit more sense so let's see we're gonna have a look at our console down here we're being spammed with one so we are currently level one if we go on our game manager and we change the x bin here to say five then we're going to be on level two if we go to four we're back to level one five is level two now we've mentioned that in between the second level and third double there is a additional 10xp so if we go up to 14 we're still gonna be level two but if we go to 15 we're finally gonna be level three now i wonder how much xp you need to hit level uh 10. you can take a wild guess it's something around seems like it's 342 so after 342 experience total you're gonna be max level okay now we know this function works we just tested it out and it worked great so we're going to create our new function called get xp to level and it does exactly what it sounds like so we're going to need a int level to know where to stop now this is going to add up the xp in xp table as long as we ate that level we mentioned up here so if we say uh get all the xp you need to hit level 2 is going to return a total of 15. so this is the total xp to reach a certain level i'll start with end r again and also int xb and as long as r is going to be smaller than level we're going to say r plus plus but before that xp plus equal to xp table at the index r and that's it once we're done return xp and we are now good to go with these two functions we're going to be able to calculate exactly what is our level and also um how much xp we need to go to the next one so we're gonna go in the character menu and start implementing those okay so i'm down here in the update menu function we have the level text that says not implemented this one fairly simple game manager instance get current level and this should return you exactly what we just tested out earlier so get current level why does it not work because this is an int and they want a string so let's do a two string at the end now for the xp bar uh this one is actually going to be a little bit complicated we're going to check whether or not we're max level first because there's two there's two states so whether you're max level and you want to be displaying something say uh just like the total amount of xp you have right now or you're not max level you're in the progress of another level so in there you want to be displaying the amount of xp you have into that level how much more do you need and uh you know do the whole progress bar thing so let's start with the easiest one if game manager dot instance get current level so if my current level is equal to the max amount of xp table entries so which is basically our max level we don't need these over here so if that is the case we're going to say xptex dot text is going to be equal to dot instance experience two string and let's add a little bit of text after that so total experience points so display total xp if we are max level now in terms of the local scale i'm going to copy this and just make sure it is a full vector 1 so back to 3.1 this is going to fill the bar completely okay now if we are not max level we'll have to find the ratio into our levels um the ratio is going to be useful so we can actually just scale the bar properly so let's go ahead and try to do this we're going to start with a new and call it current level xp and we're going to say it's as simple as doing a um a game manager instance get xp to level and we'll use our current level so game manager instance get current level oops get current level you know what i feel like we could actually put that in uh another end here so i'll just clean this up a little bit and cur level is equal to this and we'll be able to replace that and also and uh that's it okay so your current level index is actually not going to give you what i thought it would it's actually going to give you your previous one because that's the one you've uh you've completed in the past so i'll actually go back here say your previous level xp and we'll say current level minus one that's the one we need we need to know which one we have completed and which one is our current target so we'll do cur level xp now and uh same exact lines we'll go ahead and copy this but we'll remove the minus one at the end okay so we have the xp that we've already reached we have the xp that we have to reach and now all we have to do is create a ratio in between what we have and what we have to reach next up we're going to create another end called difference and that's going to be the 2 current level xp oops minus the previous level xp this is going to give you the amount of xp you need to have into that level you could also fetch it from the xp table under the game manager but i just get it here because it's it's right here and i know exactly what it does written this way now um the next thing we need to know is how much xp we have into this level so to get this current xp into level i'm going to say game manager instance experience minus the previous level xp and with these two new values over here we'll be able to get a ratio so i call that float completion ratio and we'll make sure to cast this as a float else it might actually mess up our value so current xp and 2 levels the current xp into level divided by the difference and that is how we're going to get our ratio at this point all we have to do is say xp bar local scale it's going to equal to a new vector 3 and we'll just create it here on the fly so completion ratio 1 and 1. we only have to change the x-axis that's the only one that scales okay so uh are we missing something yes we are missing one thing we forgot the text so xp text dot text is gonna equal to current xp into the level two string plus let's put some kind of little dash in between the difference and we can now get rid of these two line at the bottom here so we create a little bit of a bigger algorithm for the xp bar more than the the other ones but that is something required let's go ahead and try this in the game if we open this up we have a empty bar that says you need 5 xp and you currently have none of that so let's go here hit this guy oops we now have one sp out of five that is pretty cool do we also have the text over here yes we have the text it says level is one where then you can go back on the game manager give ourselves um say 40 exp reopen the menu and we are level four with this amount of xp and two levels so that is actually all we need to do if i put that on 32 i should be on zero out of 25 yep but i'm still level four okay well that is all we need to do for the xp uh we're missing one more function that is going to tie itself to the player and that function is the level up function so what do we do when we actually level up it'd be great if we restore the characters in point and we also give him more maximum midpoint alright so now if we want to know exactly when our player level up we have to hook ourselves where he gets xp and that it would be in the the game manager in the game manager we have this um public interview here and this one just goes up which is kind of good but it's also very bad because we don't have any way to know when this goes up it's controlled by other script what i will be doing down here is i'll create a new public void and i'll call this grant xp with the int called xp and what we'll do is when we actually have a enemy die and give us xb instead of adding it manually to experience we're going to go through grant xb and this one will be checking whether or not we leveled up so we'll do int current level get the current level right now before we do anything and then we'll do experience plus equal amount or sorry the xp that we get in parameter now if current level is still the same this is not going to be triggered so if current level is smaller then get current level right now after we gave xp uh well that means we did level up so on level up a function that does not exist but at least we'll know that we leveled up um then so fairly simple logic we get our current level before getting the experience and then we get the experience and we check again so did we level up if we did then let's go ahead and call this and that would be another function called public void on level up and from here you'll just do whatever you want so i can do a debug.plug level up and have a look in the game if this works if this is being actually it is not going to be ecologist yet uh simply because the enemy does not go through this function yet so let's go back on the enemy where he dies at the bottom over here instead of doing a uh experience plus sequel we'll do it grunt xp with the xp value so we just changed that funnel we just changed that a route so it goes through our new function so let's go in here i'm going to give myself a total of 4 experience knowing that this enemy gives me one or two um i totally forgot xp value one so it's gonna give me one xp and then i'll love a lot because right now i am four out of five i'm level one and if i go hit this guy with the sword we have the level up call right down here in the console if we open up we're going to see we're level 2 and we need 10 more xp to go up okay so everything in here works just fine let's go ahead and just give ourselves a little bit of reward for leveling up right now we really have uh nothing so what we will be doing is we could create ourselves a function under player and um you know have that have that work for us so i'll make sure to open up the player we'll create some new function here we have plenty of empty space so i'm going to create something like public void on level up and in here we could say something like max hit point plus plus and hit point would be equal to max hit point so we're pushing the cap a little bit higher say we had a total of 10 hit point before then we're now at 11 and if we took damage before that we're bumping that up so once you level up you get your all your hp back up as some kind of rewired that you know you leveled up that being said since we're only going to go up by one let's go back on the player and just remove some hb um 10 is a little bit too much i'll go like with five so player has five hit point now and if he does level up he is going to get six but first we have to hook this up to our actual code on level up is a public function so we'll make sure to go say in our game manager and say on level up on the player this time so player on level up now this is going to work great if we do level up while the game is playing but we'll need something else because once we close the game and we come back up we can't really base ourselves on this thing since we're going to have a a set of xp already loaded into the game and if we say level 4 with that amount of xp it's going to level you up but only once which is not really cool so what we'll do is we'll head back into the player and we'll say public void set level and level so once we start the game we're going to give ourselves a chance to actually set the level and uh say if that level would be 4 then we're going to call enable up 4 times let's do a for looping here so four i is equal to zero as long as i smaller than level we are going to say on level up and we only need to call this at the very beginning once we're loading the game so we're going to go back in the game manager where we do a load state where is the player level it is somewhere over here so we have the experience and then we're going to say player set level with the current level so get current level okay this way everything should be fixed i'll just create a new section for that and we're going to give this a try in the game so i'd like my xp to be a little bit higher this time once we do start the game right now this is totally fine i'm going to give more xp to the actual enemy so i can test this out he's going to give myself say 10 xp okay now testing this in game you're going to realize you already have a six hit point because level one counts as a a real thing so either you actually say well don't upgrade it if you are only level one or you could say you start up with four hp and it will get extra hp when you're ready it's really up to you in my case i'll just say if get current level is equal to one actually is not equal to one if it's not equal to one then go ahead and do this and that is going to block this problem right here so if i start a game again i should not be seeing six and here i should be seeing five now we're going to kill one enemy and actually get that six hit point uh never mind i just got hit oh but we do get filled back up so let's try this we now have six health okay now we have to test the other settings so once we load the game up if we have more than uh 10xp then we're gonna have to create not create sorry but put a set level on our character so let's go ahead and change the game manager put that on say 50. i'm not quite sure what level is 50 but we'll see in the moment then let's walk through this to have the same state called even though it's going to crash you're going to shut off the game then open it up again you still have 50 xp as you can see on the game manager and if we open this up we are level four we have nine health so this is actually working and if we kill this guy we should be level five so let's try this out we are level 5 and we have now 10 health okay now this should be everything we needed to do to get the experience part of this course completed in the next section we're going to start patching things up we're going to make sure we don't have this error pop down here once we transfer scene we're also going to fix the little glitch the visual glitch you see here that is really not that appealing and a couple of other things we could also add more ui and get the other scenes ready so i'll be seeing you guys in the next section where we're going to start just getting everything back together just linking everything together and polishing everything one by one i'll see you there guys welcome back to the final section of this course guys like we mentioned at the beginning this is the last one this is where everything is going to be closed this is it where everything's going to be linked together and we'll start um pushing some nice changes to the game that is going to make it more fun and also more playable now we've pretty much set all the system all the groundwork is there let's go ahead and get creative a little bit and um you know make this thing look good okay first thing we have to restore the flow we have this one big bug actually happens when we change scene we have to make sure we get rid of that before we go any further now i'll try to explain in depth exactly what's going on when you change the scene over here you have a missing reference exception what's going on here is that the game manager since it goes from one scene to the other without being destroyed it actually loses reference to the weapon to the player and also the to the floating text so what needs to happen is either we have a a game manager that gets destroyed in the first scene and another one in this new scene or if we want to keep it that way like it is right now if we want to keep it so every time we change scene this one persists it keeps all the data we don't have to do a a a load state again even though we do it for uh for other purpose if we want that to happen we'll have to also keep the player also keep the weapon and also keep the floating text measure we can easily do that and i'd rather have this second option um keeping everything there we can do that by going under the player and making sure we don't destroy unload this game object so this very specific game object now this is also going to make sure we don't destroy the weapon since we say don't destroy the player game object by default it's not going to destroy its children which is the weapon in this case so that is fine if we now play this game and have a look in the inspector at the game manager when we change scene we don't lose reference anymore to the weapon and also to the player we do lose reference to the floating text measure so if we had something in here that would be a problem now you probably realize that we have two of these guys over here and that's definitely not something we can um allow so what we'll be doing is we'll head back into the dungeon and get rid of the old one we don't need the old one anymore since we already have this new guy now um the camera should actually hook up to nothing at this moment so if we go under main try to play this you're going to realize we'll have another error where look at has not been assigned so we have to make sure we double click on this go under the camera motor and make sure our lookout is being assigned at the start so private void start will say look at is going to be equal to game gameobject that fine and we're looking for the game object called player and just like this i just realized that we we need to actually put the transform here this isn't a return to the game object not the transform so i went back and i have the transform now let's go ahead and play this okay so that's really cool but you realize that uh we pretty much just spawn on top of nothing and to address this i am going to create another object a empty game object that's going to be some kind of waypoint and we'll make sure to teleport the player there every time he spawns so under dungeon 1 we'll have to do it under main scene as well but under dungeon 1 i will go ahead and just move this around put it say right here at the beginning and i'll also put a little icon on it so we can see it better i will be calling this spam point just like that and it should now spawn exactly where this thing is so let's try to make it centered here could be fine we will grab this pound point put it in the main scene as well so we have spawn point in every scene in here let's actually zoom in put it in the middle there and every time we load a scene in the game manager we're going to teleport the player there so we're going to go and say when we load the scene let's also take the player dot transform its position is going to be equal to game object dot fine span point dot transform.position okay now like this we should be teleported every time the game start let's try it out and we've been move as you can tell we have been moved on top of the spawn point same thing should happen when we cross the border and we are now here at the beginning of the dungeon okay okay next up we have the floating text manager same exact thing we're going to make sure we are allowing this to persist in between scenes so here it is i have not actually put anything on top of that so hmm let's rename this to floating decks manager i'm trying to figure out why i had another canvas on here maybe i don't actually need one well i don't actually need one so i'll be dragging this script putting it back one level and we'll get rid of this uh this little children here because that's kind of useless for us we only need the canvas i'm gonna go make sure i haven't broken anything and i have in the references so i'm gonna go back in the game manager driving drag and drop this new object and let's see what is the other problem so we broke some references as well somewhere else in the floating text manager we have this reference we broke it is directly under the same object we are going to drag ourself in it and then hopefully everything is back okay so everything is back we just have one less object in here which is making it a little bit more clean now what we'll be doing is we're going to make sure this one gets never destroyed so i'm going to double click on it and in a start private void start i'm going to make sure to don't destroy this object when we load just like this now um if you want to keep the same exact way as we had earlier for some reason you have a two level um floating text manager you can always say transform parent game object this would work if we had the same exact setup as we had a second ago but right now since we cleaned it up game object is going to do the job all right so let's give this one more try we are going to switch scene see if the reference is still there and it is so all the reference are kept even the pull behind it is kept and we have everything we need to proceed polishing this game hi guys that will be it for this lesson i will see you in the next one where we'll go ahead and try to fix this annoying little gap we see in between the tiles see you there welcome back to another lesson today we're going to be fixing this annoying bug we see this visual bug we see with the whole map trying to um have these little blue line in between the tiles and that is something really really annoying and this should only happen if you have very very low resolution in our case we do have an extremely low resolution we have tiles that are 16 per 16 and our camera is literally really really close now if our camera was further away we'd have less problem but you see we still do get some so what we're going to be doing today is we're going to be changing some of the texture setting and it's going to help us have a better result so we're going to go on the atlas the only piece of art we have in this whole game and we're going to go at the top here have a look at the settings the most uh important one that we're going to be using is the pixels per unit so this is going to let us scale down a little bit on our texture it's going to actually make it bigger make everything a little bit bigger and forget about the edges so if we put that on 99 and hit apply you're going to see we actually fix most of the problem already i don't see anything um going on there we can play with this because we know that like that one last pixel is the one that caused problems so with 99 we have a result that is pretty solid now i'll give you an example if you put that on 50 it's gonna make everything look so much bigger and so much more weird so uh it's very simple you just have to play around with this until you find something that matches your art in our case 99 would be the best setting you could also try something like 95 but there's always going to be little visual problem as you can see here on the outside we have all these squares and the reason is quite simple our art is too low definition to make that look um like pixel perfect you could go ahead and try out any number you want um mine worked best with 99 but of course if you want to be the cleanest possible you'll have to just make your art a little bit bigger or make your camera further away so that is all we needed to do to actually fix this little glitch uh right now looks pretty good i don't have so much problem going around sometimes you're going to run into visual glitches but i haven't in a little while so i'll be keeping 99 guys thank you so much for watching we quit i will be seeing you quit what am i doing in the next session in the next lesson we are going to put okay quit in the next lesson quit in the next lesson we're going to turn this scene into something playable quick in the next lesson we are going to start creating something a little bit more fun for the other scene for the dungeon scene so something that has a real flow so you can go back to the main scene you can kill the boss and you can do a lot more thing right now we can't really do anything in this new scene welcome back to another lesson in this one we are going to start creating a flow in between our main scene and then the dungeon one um we are back with the the dungeon one we've done in the section three before that i created a dungeon for the course i realized it was a little bit too complex at first so i went ahead and i redid it the one i've redone is the one you saw in the section three now i am back with this with this new um well new but old uh dungeon over here so this one is quite simple this is where we'll be placing most of the assets and this is where we're going to be um creating our flow so we have the main scene right now right here sitting it has a couple of things we have to transfer over to the actual dungeon one first off all these chests let's get rid of them let's clean them up we're gonna remove also the enemy but before we remove it let's put it inside of a prefab so we can save the settings over here then i'm going to remove it um the portal will need something similar for dungeon 1 and what else is everything clean here i think we're pretty much good to go okay so to transfer over to the dungeon one we're gonna have to grab a couple of thing player it is something we don't destroy unload so we don't grab that main camera already exists on the other scene we don't grab that test in pc it's just a test right now we leave him here we are not going to grab this grid of course we won't be using it then there is the portal which we are going to grab we are not going to grab the game manager evan system as well uh floating text manager we are not going to grab it we don't need to since there is a don't destroy unload on it as well so we'll need portal menu and spawnpoint i've been selecting those using control and click so i just control hold control and i click now once i have all of these four i'll do a ctrl c for copy head over to the dungeon one and just space and here is everything we need now if you wanted to what you could do is have the menu and have the hud don't destroy unload but you have to implement the same exact kind of mechanic we've implemented on the game manager so once we go back to the main scene those would be duplicated so you have to make sure they actually they don't exist while another one of these exists so let's go ahead and take the spawn point first and i'll just move it where i believe the player should be spawning and what is this little mistake over here okay it's back to normal um i will be putting that right about here and in terms of the menu that's fine hud is fine now the portal is something else the portal is something that is not fine so i'll be putting it somewhere say around here i want to have a gate that goes back to the main scene and i think i'll be putting it right on top about there okay now you can also play around with the collider size i'm going to have like two black square that go into the wall and i'll put some torch around it just to simplify that that's a door later on but until then here they are if i can keep on editing this thing okay so if the player enters this collider he is going to be teleported to main we have the option to change it down here so that's pretty cool now i'm also going to create another portal exactly the same as this one at the end so where the boss is i'll put it somewhere right here so once he's done killing the boss the player can exit using this portal same exact concept okay um the script is exactly the same as well everything should now be good to go and we're gonna go back in the main scene give this a try so we're just walking around we're going to go at the top here we should be teleported in this scene now a couple of bug a couple of things going on right here we don't have to look at on our camera so we forgot to transfer that over let's go back on the camera there is this camera motor script we want to grab this so i'll just do a copy component go on dungeon 1 find the main camera add a camera motor paste my component values now you'll see that the lookout is actually missing but that's fine because we set it in the start in fact since we never actually said it anymore in the inspector we could go ahead and remove that from a public field turn it into a private one instead so once this thing loads up i'm going to turn my public field into a private you could also leave it public and add a hide in inspector if you really wanted to but in my case i don't need it to be public at all so i'll just be leaving it like that and now the field is going to disappear okay let's give this a try under main all right so we'll be giving this a try from the main scene and i'll head right into here uh the camera is back in focus we are there with our little weapon and there should be the gateway just a little bit above me right now so we'll give it a try walk right through it and as you can tell we have successfully went back into the main scene now obviously you're going to find that there is a bug a big bug here on the fact that we can have two player at once which is not very very cool and those are both don't destroy unload so technically yep here it is oh also one other thing i forgot as i am doing it is that we didn't bring the event manager which means we can't click on our button and that is a big deal so i'll go back on my main copy over the event system not the event manager the event system put that in the scene anywhere anywhere you just need to drop it in the scene and this one is going to take care of looking at where your mouse is and what you click on so let's go ahead and start this from the main scene if we don't it's simply going to crash since we don't have a player i'm going to go right into the dungeon one click here menu is still there everything still works and we are pretty much good to go and now the next step is going to be to actually remove a couple of bugs so the bug you saw earlier where we have two players the next step is also gonna have to deal with creating content for this actual scene here alright so that's about it we're going to keep on doing those fast lesson in the section 10 to make sure we polish our game as much as we can before we end this course thank you so much for watching i will be seeing you in the next lesson welcome back to another lesson in this one we're going to fix this book where we have duplicate amount of character and floating text manager and we're also going to start populating our dungeon one so let's go ahead and uh the first problem we have is the fact that we get duplicated amount of floating text manager and also player now we don't have the same problem for game manager even though it is also don't destroy unload and that is because we have this line over here so so if a game manager already exists we get rid of the new one well we're also going to do the exact same thing actually at the same exact place but we'll be adding um our new player and also our new floating text manager so we'll do player.gameobject and floating text manager dot game object this way once we transfer back to the main scene those are already there in the scene but we want to keep the one we've been using um for a long time so as you can tell the new one they got deleted and we still hang out with the same exact stuff we had prior okay so having this completed we are now going to move into this scene and start creating a little bit of content around here so the first thing i'll do is just make sure i um i create a visual aspect to my portals now i know i have one at the beginning right here so i just open it up so i can see it and i'll be changing say uh these two tile here to black dial okay now my portal is going to be in here i'll just make sure to adjust it properly like this and i might also want to play around with the collision of this so i can just create some kind of hole in here but before that i'll go ahead and i'll move on to the boss portal which should be around here like i mentioned having this completed i'll hop on the collision layer turn the thumbnail around just so i can see and just change the collision a bit go like this instead and open up those two slots and here we go so we fix our tile map we change the level a little bit and we're now going to turn off our timelap renderer again okay um for the sake of just filling in stuff i'd like to see what's going on on the left hand side so i'll turn off my menu for now and it looks something like this okay now um i haven't done any kind of level design for this thing but we're gonna start dragging chess and we'll just put them where uh we think they would look good so at the moment we could put just say right about there or here you know let's just put them a little bit randomly at the moment since we don't really have anything and we'll be putting some in the back of the bus room now you're also going to be aware that you can actually just put one chest and modify the values the amount of pesos you get this one could be say 30 pesos it's a big chest that's the one you get from the bus in fact you could even modify the scale and make this one a little bit bigger and i'll just place it here now these two chests are small chests five pesos each could be perfect and we'll just leave that somewhere around here okay now what i'll be doing just to make everything a little bit more ordered is i will create a empty game object put everything back on zero and i will call this one chess when s and i'll just put all the chess right in here this way we have one big object that contains all the chess and if we need to do some kind of operation on it we can do a mass operation on all the chess so in this lesson i would like to tackle the healing fountain so this thing at the top here i want this to be giving hit point back to the actual player if he is injured so i'm going to go ahead create a new script that's going to require a new script call it ealing fountain ealing fountain is going to inherit from collidable and we will simply override the uncollide function as we've been doing for a bunch of our classes let's start with a public end ailing amount so how much do you heal every second uh you could go ahead and say one then private float ill cool down actually i said how much yield every second but you can change that to 0.5 if you wish just use this value over here and then we'll keep another float for the last time you've yield in a protected override void on collide we are going to create our logic right here so if time that time so if right now minus the last time you've yield is bigger than the cooldown then go ahead and heal the player so lasso is gonna quality now and now we have to heal the player we don't have any function to heal the player but that should be quite simple let's actually create one on the fly so game edger instance player will call it ill and you'll alien by healing him out okay so we can go ahead and um enter the player.cs in our very empty player script it's getting a little bit more crowd now but we still have like a lot of space to put a lot of stuff we're going to create a public void ill that takes in the int healing amount the healing function is going to do the following so hit point is going to be plus equal to the amount of hit point you get so ealing amount and then we'll check if we're above the max amount so if it point is bigger than the max hit point then we'll have to bump that down to max hit point so hit point is equal to max hit point and else if we actually uh if we're not max then it means we did get heal and if we did get healed we're gonna do game manager instance show text we're gonna show a little bit of text in here some green text uh plus sign plus the amount so the healing amount two string plus hp for hit point then we can have a size 25 color is going to be a nice little green do we have a light green uh we could create one but right now i'll put it on green add the transform.position and emotion yeah we could use emotion vector3.up say times30 and we make it stick for a full second so now i just realized that there is a flaw in here if our healing amount is above one if our healing amount is above one um we might trigger this over here without being full hp so we're still going to get ill but we won't trigger this deck so what i'll do is i'll just swap that around maybe go for something like this instead and we'll just check right off the get-go so if if the hit point oops is equal or bigger actually if the hit point is equal to max hit point we're just going to return so we don't need to go anywhere else so if we are max set point we're not going to do anything but then you still have to do the clamping so if hit point is bigger than max hit point then hit point is going to be equal to max hit point but you still have to do the show text because you did ill and that should be it i believe okay let's go ahead and implement this in the game i'll be dropping a small enemy in here just so i can take some damage let's put him right in the middle and now we're going to create the ailing fountain as far as the healing fountain goes i'll create an empty game object and i'll put a collider on it so let's call that e-link fountain i'll be putting a box collider 2d and i'll be putting the ealing fountain script i'm going to make it a little tad smaller and also position it properly it is going to be right around here at the top so when the player is inside of this he should be ill now i did not put that on default i did not put that on acta or anything like that and technically if i remember uh correctly this should work and we're gonna give it a try so let's go right ahead jump into the action see if we get hit yep we do get hit um for some reason i did get heal right there i'm not quite sure why oh alright so it turns out that the the fountain actually collides with with the wall and then we get the hit point because we never do a check to know whether this is a player or not so let's go back and on the e-link fountain we're gonna say if call dot name is not equal to player then we're going to return so we're not going to run the rest of this code now let's go back and try this once more don't forget to turn on your menu again else this is going to crash we have a total of 15 hp right now let's take some hit and kill this guy 11 hp is what we have and then if we go to the link found nec we are going to gain some it point back until we reach 15 and then we're good to go again all right so this is where we'll be ending this lesson in the next one we're going to be creating some objects we can destroy with our sword see you there welcome back to another lesson today we're going to be making a destroyable object that we can simply kill with our weapon you're going to laugh at how easy this is let's actually do it in a matter of lesson minute we're going to right click on script create c-sharp script i'll call this one create because i'll be i'll be using crates as object i will destroy now we have to open up visual studio which is the longest part of this thing and we're until it boots completely and here is what we do we make this inherit from fighter and we override on death to give it something like uh a destroy game object and that's it that's all we need to do to make the um the great object why exactly is that only it well we're gonna go back and dive into fighter really quickly we have hit point we have max hit point uh so so our crate already has some hit point values it is also immune for one second we already have all of that it has a push direction but since it does not inherit from mover we never really use that uh worst case scenario you have to push direction if you want to create some kind of special effect in like and send it in in a direction you could do that it's really up to you you have the hit direction so something you might want to do in the future and finally you have the receive damage so everything is already there the only thing we didn't have is the destroy call and to be completely honest we could be putting it in here and not even have to worry about putting anything in crate.cs but we've done it and we created our crate now how do we go about testing this out it's going to be very simple we're going to spawn the crate now there is two crates over here there are actually three crates that are bound into the tile set and that's kind of annoying because if we want crates to be destroyable in our game and we put those here that are not destroyable simply because of the reason they're not destroyable here is because they are a hole and they are in tile map so it's going to be odd to put collider on those and put the crate dot cs uh by the way i actually want to go back and remove those from tile map and just spawn some crate on top of it later on so we'll do that at the end of the episode but let's actually go ahead and go under artwork atlas find some crate i'll use create 0 and create one not sorry not create but create i'll just drag these two at the same time oops not in here so one time all right create zero create one and we will be moving them say over here give them the interactable layer so we can see them and i'll make them match as best as i can actually if you hold v on the keyboard while you're dragging over your object you're going to see you can you can actually snap on those little points so we'll snap top left drag this down here so it snaps on this one as well now this whole crate is one object we're going to create one object empty game object and this one's going to be a single crit put the origin on 0 0 0 then take the two crates put them in here so i have one object that contains these two together i'm also going to make sure i just position them properly at 0 0 0. there we go and i'll just fix the mess i've done go back just making sure it's clean basically that's what i'm trying to achieve here so this goes there okay now i can actually move the single crate using the bigger object and it's going to move the whole thing as a whole right so what i'll be doing right here is i'll use a box collider 2d again make sure this one fits my my need so i'll go for something like this and we should be holding the collider properly at this point what i'm going to do is uh i'll put that back on zero zero make a prefab out of it by drag and dropping this in the prefab folder and the reason i'm doing this is simply because we'll be reusing creating the future in fact this one is not completed i forgot to put the crate dot cs on it and also um the layer at the top right now we have a a crate that's gonna do what we wanted to do so if we go here hit it it should actually do something nope because it does not have the fighter tag uh if we want this great to receive damage it has to be under the fighter tag and now that's fine we can hit it the only problem is that as you can see we can just go on top of it which is kind of annoying so let's go back on our crate put the tag fighter and also put the layer on blocking this way we are not going to be able to run through it so we're stuck here and then we're going to start doing damage with this thing until we hit tenant point and here we are we're free then it point might be a little bit overkill for crate i'll be putting two uh or even one like you can only one hit this thing that could work as well really depends on what you like the best and once that is completed make sure you hit apply after cleaning your object make sure you hit apply so this applies to your prefab object okay now having this completed where is my play oh it's behind the crate okay having this completed i'm going to move these away and actually put create that are destroyable so i will be doing that right now just matching this object and then let's go ahead and find the other crates here they are so two and three create a object for that call it two crates give it the fighter tag the blocking layer and then we're going to drag these two guys beneath this object so it becomes the children and let's put them on the interactable layer and here we go so just snap this here we go we have everything we need create a cs a box collider 2d and i'm not sure if we want this one to match exactly the last one we'll see what we can do with this you know what let's actually make it match there we go oops i keep clicking next to it this is really annoying all right so this one could be a little bit more tough it can have three hit point and we are then going to save this under the prefab as well so let's move this on top of this one try to be pixel perfect if you're not that's not a big deal and then what i'll do finally is i'll just turn those off for the moment and i'll go in my tile map try to get rid of what we add earlier so which one contains the crate so design is the one that contains the crate i'm going to go right ahead shift click these things oh sorry i have to be under design here then i will be shifting these things and since we're here might as well add a little bit of shadow right there there we go looks pretty right we're going to turn on those crates again and same result as before but this time we can actually go ahead and smack those crates and they disappear cool stuff so we have crates let's go ahead and put some in our other map so let's head over to the scene dungeon one and i'm simply going to be placing some uh in the middle here so it blocks the way so the player knows he's gonna have to use his weapon um and if he doesn't know well we'll have to teach him in some ways maybe by putting an npc that say hit the crates that could work um what happened oh i'm still i still have my uh brush right here so i'm gonna make sure i actually close the tile palette i don't want to be making any modification um without really meaning it so let's play some creating here that's fine we can also put a single crate just below it and it should still be blocking we can even give it a small offset that could work two crates like this and i just want something that blocks the way basically so maybe put another one down there well the player cannot move with these in the way that's for sure now is that the best placement that looks the best i don't think so maybe something like this could be better okay now uh let's actually give this a try so if we go in the game we head up in the dungeon we can't move we have to destroy these grades there we go those are our very first object we're starting to get a little bit of the gameplay over here we have the e-link fountain the enemy the chess um and of course the crates in the next lesson we're gonna have a look at how to create those little animated sprites that are going to be some torches we can put them around the doors over here so that's going to let you know that this is a door that's like a little bit of graphical upgrade we're going to put in here okay so we'll see you guys in the next lesson welcome to another lesson today we're going to create a sprite animation there is a couple of ways we can do this but with the new system it is fairly simple let's actually go find our sprites at the bottom here under our art atlas now we already cropped those um properly so they all add the same size they all add the um the same exact width the same height and by having those already cropped out like this all we have to do to create the animation around that is to go ahead choose them in the in the sprites down here and just do a shift click on everything and we'll be able to drop that right under the iron key this is actually going to create you the whole animation by itself we can call that one torch and it will also create a animator and also animation so we'll go ahead take this drag it under our animation folder which should be at the top here and we'll have a look at what's going on because it's already done we can already drag this wherever we want so as you can see we have the torch one in the scene i can put that on a more visible layer such as wall and you'll see that if we play the game the animation is already live now um i haven't started from torch zero because torch zero is no fire at all so that would have been weird in the middle of the animation okay so let's have a look what exactly happened here they have created a animator with a animator controller which we can see here i'll just rename that to torch and rename the animation to torch with a small t and under that animation you're going to be able to see what they do so let me go and open up the animation window all they do is they put all the frames we put in the the scene and they just put a different sprite every single frame so sprite 0 is if we click on it it would be torch one sprite torch two three four five i'm looking at the right hand side over here so that's exactly what they've done you could have done it manually i remember doing it multiple times manually but i um i found this new tactic now and it's so much easier you can just drag and drop this in the scene and they will do that for you i thought it was kind of important to show what's going on in the background in case for some reason it doesn't work for you and also remember that this is a uh this is under the animator so if you think this is too fast you can go ahead and manually change the sprite or you can go back in the animator click on torch which is your animation and make that uh slower so say something like 0.7 and i am quite satisfied with 0.7 so i'll go ahead and just put the rest of the information we need on this storage for it to work starting off with a collider so a box collider 2d and i'll open this one up it looks like this i think that's fine um we'll also put a layer that is blocking actually the collider i'll just make that a little bit smaller so you can walk behind the flame all right here we go okay i'll rename this to torch and i will be saving it under my prefab folder so let's go ahead and get rid of this one we're gonna go in dungeon one and just put that next to our gates we have one torch that's gonna be right about there and another one on this side i'll be copying these two and moving them over to the other gate which is right here okay now if we play in the main scene we go directly in the game see how this looks i've played a bit as you can tell i have the sword it now looks like this so we have some moving sprite in the scene it looks a lot better than if there's nothing of course and the more you add moving stuff in your scene the more it's gonna feel alive so i do encourage you to find other kind of sprite you can move around because those make a really huge difference now in terms of moving the player around it would be the exact same thing but you'd have to balance in between different states so if he's idle you put him in a state where there's only one uh frame of this very specific pose right here but if he's moving every time he's moving you could do that with a set float or a set trigger on your player state machine you could say well if he's moving you're now playing that animation where he just moves his feet slightly and if speed reaches zero or if uh the trigger idle is being activated then you just put him back in that state so it would be a mix of what we just done right here with the lights and also a mix of what we've done for the menu animator in the next one we're going to be adding a it point bar on the left hand side over here and fixing some hp bug welcome back to another lesson today we're going to expand our hud this way we can have another kind of hit point bar but this one is not going to be in text and it's not going to be in the menu it's going to be live in the game i'm thinking about putting it just above this little chest so let's actually get started so it's going to be quite simple what i'll be doing is pretty much the same exact thing we've done for the xp bar so under hud i will be creating a new image in that image i'll make sure to anchor it bottom left i'll give it exactly the same size and the same offset as the chest so let's go ahead and go down maybe 75 and as far as the width goes we'll go on 64. and the height is really up to you we could go up to 125 and that would be my uh my hit point bar over here in terms of the background color i'll be using a dark red color something like this so i'll be calling this helba and under it there's going to be another image exactly the same so ui image this one is going to scale on both axis so i can get the size put that on zero and then back to the bottom axis i'm holding shift this way it hankers at the bottom okay this one has to be a brighter red so something like this and all we have to do at this point is play around with the scale not in x but the scale in y so it goes up like this and down okay so having this completed all we have to do now is the code beneath it and we'll hook this up at different places but um the first place i'd like to hook this up actually is in the game manager and in the game manager there is going to be a function we'll create if we just collapse everything um we could go right about here and just say hit point bar and create a function called public void on hit point change so this happens once you uh get hit but also when you get healed which is why we can't just put it at one place in the code it has to be in the game manager because the fountain is going to be calling it the enemies are going to be calling it and so on so we'll need a hit point and also and max hit point we could also fetch those manually from um the player but it's really it's really up to us we could do player dot hit point this is you know this is public so we could technically go here actually i like that better so let's go and remove these and all we'll have to do in here is get the ratio so ratio this time it's not going to be as complicated as um that's what we had earlier for the experience and that is because we have we already have our two values we already have hit point and also the max hit point so player hit point divided by float player max it point and we already have a ratio at this point we'll do hit point bar which something we don't have at the moment i totally forgot about that let's go um in the fields and we're gonna get a reference to our hit point bar and we'll get it as a rec transform like this let's go back down hit point bar dot local scale is gonna equal to a new vector three one ratio and one remember we're not modifying the x in this case i made the bar vertical so we're going to be modifying it i'm going up and down now coming to think about it we don't need to put it inside of the healing fountain since we can hook it up in the heal function inside of player so we'll have it at two places and here we'll have it on the unreceived damage and also on the um heal function we have right here right now unreceived damage i don't think we have it in there we'll have to override it so let's go ahead and do that we're going to create two new function actually only one um that one's going to be a override so i'll put it with the override at the top there protected override receive damage and we still do the base we don't want to mess around with anything else we do the base and then we do game manager instance on hit point change and we'll copy this line over we'll also need it when we get yield so down here if we do show the text then we're going to go ahead and say uh update my ui as well having this done we're going to go in the game manager and find our reference it is right here let's go ahead and drag and drop this hit point bar the last one the one that is bright under there alright so we're gonna actually take this and copy it over to the other scene because we don't have any enemy in here i'll go under the hud take my health bar and my health bar is going to be transferred over to dungeon 1. make sure it is under the hood else it is not going to be rendered simply because it needs to be under a canvas to be rendered okay let's go ahead and see what's going on in that scene now um i've already leveled up already played the game a little bit so i have 21 health right now which is another problem but let's see if we do hit get hit so okay apparently the object has been destroyed and we can't access it anymore which means our reference was not a good one simply because those are being deleted when we swap scene okay now because we put that under the game manager we are going to run into a problem simply because once we change scene this reference is going to be lost uh we have to make sure this one stays throughout the scenes and the way we're going to do this well first we can either do that through the scene like i just mentioned with a don't destroy unload or we could also say um this is going to be equal to whatever the name of our game object is there is two way actually there is more than two ways in programming there is always a couple of different ways you can work on these things if we want to be really lazy we could go up in the update and say don't destroy unload and just take that hit point bar that game object and this would technically work so now we could be lazy and just do that but what i'd like to do instead is to create a whole new script and get rid of all my destroyal node they're a little bit hard to track at the moment so what i'll do is i'll just get rid of them all i'll hit ctrl shift and f find any more don't destroy which are going to pop up down there so we have one under the floating text manager we have one under the game manager and we have one under player so i'll be getting rid of all of these i'll create myself a new c sharp script and this one will be called don't destroy simple as that all it's going to do is at the start or at the awake let's do that in the awake actually private void awake we're going to say don't destroy game object and uh sorry don't destroy on load game object now i'll go back on every single one of these object that i've deleted from and i'll just add this component and just having this component is going to tell me that this object now persists so that's going to be quite useful right next up we have the game manager don't destroy we have the floating text manager which is a don't destroy and let's also don't destroy this hood like the whole button and this hit point bar this way i won't need to have it over here so i'll remove it that's from dungeon one now since we're here let's also get rid of the menu let's also make sure this one is not being reinitialized every time so i'll play don't destroy on that one as well and we're going to realize that most of our work is uh pretty much being duplicated once we go back in here so now we have two hud we have two menu kind of a mess we don't want that to happen of course so but um we're gonna have some more reference at the moment that one's gonna be a uh it's gonna be a game object actually that's gonna be a hud and then a public game object that's going to be the menu and i don't know why i put those in cap i usually don't so let's go ahead and turn that back into small letters at the top here we'll be destroying those two things those two new things so hud and the menu okay so we're basically destroying five things now as soon as the game starts not that optimal but like i mentioned we're going to have a small lesson on how to make this more clean and more optimal of course so back on my game manager let's go and drag this so that's my ad and that's my menu i just needed the reference only so i could destroy them later on let's play this see if it works we are in the new scene the menu still works looks accurate we go back here and we don't have any duplicate i don't think so so everything that actually passes through both scene our thing that just stays there all the time so that's pretty cool that's a good way to do things and now um you can barely see it but i did take some damage which means our hit point went down but her hit point if you have noticed every time we change scene our hit point actually glitches a little bit we were at 36 now we're at 45 now we're at 53 so you know it just goes up uh when we change which is definitely not something we want and it's something quite annoying the beauty of what we just did right now is the fact that we don't have to do the load state anymore since we're already like moving everything we we know uh from one scene to another including the game manager the xp the pesos all that kind of stuff is being moved over we don't need to do the load state anymore so we only have to save like a real game so you would only save save save and at the beginning you load once so we don't have to do the load state anymore let's double click on it head over to the load state i'll be removing those debugger plug since i'm here and we'll make sure that we actually remove that from the events so just like we did in the awake over here where every time we load a new scene we're going to do a load state we're going to remove it right about this so actually at the beginning we're going to remove it we're going to say scene manager c noder minus equal this function so the load state now with this in the way we should not be able to have this stitch anymore so we're currently at 13 hp if we oh if we head back here of course there's going to be something to be done because we're being teleported somewhere quite weird but at least our hit point is fine and we can now try and fix this problem now what's going on here is since we remove the load scene we also remove this call at the top there which is something we want to keep on doing so you want to be splitting those in two and let's create another function for on scene loaded we'll make it public boyd actually will copy the same exact thing we had here public void on scene loaded and inside of here we will simply do what we need to do every time in using load in that case that's going to be our call which i unfortunately deleted so i'll just rewrite it um it's gonna be something like player dot transform position is equal to game object dot fine span point that transform that position make sure we add this at the very top so in the events so when we load a scene scene manager scene loaded plus equal and on scene loaded here we go so now this one is going to be called every time we load a new scene and this one is going to be called only the first time we load the scene so that's also um when the game loads technically you could put the load state instead of some kind of start or update and that would have worked as well okay so we should be good to go at this point we have fixed this problem we don't have anything else to do with the hp let's go ahead and get hit see if our hit point bar goes down so it does as you can tell and the only thing left we're gonna have to do with hit point is whenever we die we're gonna have to show some kind of menu um you know so the player knows he's dead something i quickly forgot while i was playing the game was testing this out is um the fact that we don't call on hit point was change uh when we level up like right here i just killed this guy i leveled up but we did not change the hit point but we know that um whenever we do get a level up we're supposed to be max on hit point as you can see on the top right side over here so we have 14 in point out of 14 which means if i go on the fountain uh well this happens so we don't know that we're full hit point because the bar is not topped if we click though we can see it but uh you know but this is not really what we want so let's go ahead and put that as well on the on level up which should be under the game manager and we're going to go on on level up make sure we call on hit point change okay so that's the little addition i had to do before we close this lesson welcome back to another lesson in this one we'll be adding a free to use font and a free to use commercially font which is also very important if you plan on monetizing your game we are on a website called 8001funds.com and here we'll be looking for something that is actually um our style so i'll go maybe with something blocky which is definitely not our style something more pixelated would be good but this website has a ton of different phones you can have and as you can see they also have like sections so pixel is what i'm looking for this could be good for our game we have to make sure that this little icon over here is green so it's free for commercial use sometimes it's red which means it's free for personal use but you can't use that on a monetized project something really important to do as well when you're looking for fun is to make sure they do have the character you need so in our case uh we don't really have any special characters we have the plus sign and that's pretty much it so let's do plus five here see what it looks like when they print it oh and um i think i'm gonna be rolling with this one pxl by levy so actually this one is not free for not not free free commercial use so let's go ahead and move up to maybe another page and see this one is pretty similar it looks good it is free for personal use and commercial use so i'll be downloading that and all we have to do in unity is once we have the fund extract this make sure you copy the fonts so there's two fonts in here make sure you copy them so just take these two font copy or cut and you're going to go right inside of your game right click in your artwork folder showing explorer and just paste them in here they're going to be loaded up and it's it's quite cool because that's all you need you don't need anything else there you just need to put the font in there and unity is going to recognize it so okay now if we want to use it inside of the game for all these menu we have to go back on these and actually set the font to something else so i'll go under menu uh we have the container the equipment equipment has only one text it is the upgrade button text and we're going to change the font from ariel to this and here we go we have the hundred being written in such a weird way but uh you know 75 is not so bad all right so uh from here you now have your new font size so it's really up to you to decide whether or not this is too big or too small i don't dislike this so i'll just be putting that in different color maybe a little bit more gray like this that could work and you're just going to go with the feeling of what you like the most now this one i unfortunately don't have any icons i can put so what i'll do is i'll just put a text in here and that text is simply going to be an arrow something like this that's all i have unfortunately i don't have any uh ui pieces done so kind of annoying but at the same time that's gonna do the job for now okay let's go ahead and scale this up that's our arrow you might want to remove the dash and let's look at what it looks like in a different font so in a different font in this new font it actually doesn't look that bad now i think about it we'll be duplicating that putting it under the right arrow as well then put that on left hand side or right hand side and here we go so we have this moving on character information this one is pretty much only text so what i'll do is i'll just grab these six decks label and change them in one go okay so that's fairly cool i'm going to need to up the size of these maybe like that and then up the size of these as well maybe give them a bigger margin and here we go we have something like this now looks a lot better and to be consistent we also have to do it on this okay so our font is definitely a lot different than what it was before but it's still there it's still readable still looks good that's max and where else are we using font we're using font in the floating text as well so if we go here as you can see those seven they don't look too great those one don't look too great the cool thing about this is we only have to change it at one single place and that single place would be under the prefab so for floating text prefab click on it put that on the new font and we should now be good to go now speaking about floating text i was thinking about doing it a long time ago but we're gonna do it uh in this lesson we're gonna give some some text to the npc so the npc never speak he never does anything right now he's just sitting there and calling the really annoying um default on collide so let's go ahead and give him some text and to do this i will be creating a new dot cs class so i'll go under script call that intro npc or even better we could just create a whole new class for those kind of little dialogue guy we could call them npc text person whatever you feel like really and what we'll do is we'll create a public string that's going to be the text and this is how we'll be changing it from different npcs make sure we override on collide so on sorry not on collide collidable and then we're going to override on collide so protected override on collide public string message and when we do collide all we have to do is the following so game manager instance show text let's show our message the font size let's make that like 25 um color color dot white it's gonna be very very neutral we could also make it like change at the top here so you can have a public color and change it directly in the inspector as well uh position is gonna be transform.position no motion on this one so vector3.0 and it goes up for a duration of about three or four seconds something very very long so they can read okay now having this completed let's head back on our little guy so where is the test and pieces over here let's call him intro npc now he deserves to have a new name and instead of having a collidable script we're gonna have the npc text person as far as the text goes we're gonna say something like uh welcome to the course hit the boxes with the sword for no reason okay right and if we do welcome him now he should be shouting this oh it is quite annoying and the reason it is quite annoying is because um as you can tell it's being repeated like there's no there's no downtime at all so let's put a cool down on this thing cool down could simply be the same exact way as we do all cool down so private float cool down we'll put that on 4 private float last shout and we're going to do a if time minus last shout is bigger than cooldown then go ahead and say what you have to say let's make sure last shot is also equal to time that time and i'll replace this by the cooldown here we go should not stack the same way it was stacked before so he goes like welcome to the course hit the boxes now um this is a little bit annoying because the text is on top of the guy so we don't really want that what i'll be doing is i'll go back on the code and i will actually change the transformed position to have transformed position plus uh the best case scenario like to have it perfect is we would go ahead and get the box collider 2d then do something like that size or dot bounce do we have bounce they do have bounce nice that center actually bound extend dot y and that way that would be above the actual collider of this thing so we could either do that um or we could just set it a manual value of say vector3 dot up this way does it one above where it should be now something you probably notice as well is that he doesn't start speaking at first we have to wait four seconds which is not what we want and also vector 3.1 is a lot is a lot too high um so we're going to reduce that but to fix the problem where he does not speak for the four first four seconds that should be quite simple we have to make sure that last shot is equal to minus cool down at the beginning now we can't do that we can't we can't really assign that to another uh field at the top here in c sharp so we can either do -4 menu like this or we could go ahead and make it clean so say public void start last shout is going to equal to minus cooldown this way when a game starts actually this one is being overridden so you might wanna do a protected override at this point it's getting a lot of overhead for almost nothing but i would suggest you just go with last shot is equal to minus four in this case um but in my case i just did the whole thing okay so this should appear instantly though it's going to appear very very up far up so we're going to go back and turn that into vector3 up time 0.16 or even better new vector3 0.16 actually 0 then 0.16 and then 0 again so it's going to be 16 pixel above the player which should leave a little bit of space in between the head and the text there we go welcome to course hit the boxes for no reason amazing so we just changed our text pretty much everywhere i don't think we have any more text um laying around that uses the old font so we are pretty much good to go and that will be the end of this lesson in the next lesson we'll be adding a really big boss at the end here welcome back to another lesson in this one we're going to create a boss that has a special ability a little bit different from this small enemy we have over here and uh since we're here i just killed a small me i just want to show what happens when you are max level currently level 10 uh i have 15 health should i have 15 health i kind of took a damage real quick let me go ill there we go so 15 help i have this amount of pesos and this is what happens with the xp bar so it says your amount of total xp right now okay now today would like to be placing a boss in here and we'll be adding a little bit of different abilities because of the small let me just rush towards you then the bus i want him to rush towards you as well maybe not as fast and i also want him to have stuff rotating around it that could hit you potentially so let's go ahead and crop one of the monster out of the atlas so which one could be good let's actually use this one it looks funky so i'll be using that um let's see we can make it 32 by 32 that would be perfect and we're only one we're only missing one pixel in height so i'll be taking it higher like this so i'll call this bus underscore 0 and that is going to be it i believe let's click apply and uh since we're here let's also grab some of these little guy because we'll need something that orbits around this now this is kind of ugly so we're going to take a something that is also ugly maybe this little piece of fire here this little uh dropped out of fire let's make that 16 16. and i will be calling this enemy underscore one okay let's hit apply we're gonna go right into the dungeon so let's open up this new scene and let's go right at the end here so at the end of this dungeon i'll drag and drop my boss underscore zero put it in here make sure it is on the actor sorting layer and uh should we make it bigger is that big enough we could go ahead and try to duplicate its size that would be a lot way too big actually so let's put that 1.5 and here we go now um this one is going to require a new boss dot cs so let's just call that boss it's a new c sharp script we're going to create it put it in the script folder so we don't leave it hanging there for too long and let's open it up and actually code a little bit of that so what i'm going to be doing with this one is i will be creating a fireball that orbits around the boss and this is very very simple to do in fact i kind of inspired myself from a old video i've made in the past the third person camera i've made in the past and i will be doing pretty much the same exact thing here so what's going on is we're gonna need a speed for that fight actually before anything uh we're gonna have to inherit from not even fighter i still wanna have the same behavior as enemy so we'll inherit from enemy this way we can grab the the moving behavior and um on top of that there's going to be a little fireball so boss is going to have this public float called fireball speed i'll put that on something like 3 or 2.5 we'll see it's public so we'll be able to adjust it while the game is playing and in a private void update every single frame what i will be doing over here and i don't know if i'm actually allowed to use the update um the enemy seems to be using a fixed update so i guess we're going to be fine here what i feel like doing here is the following so we're going to have maybe one in me or two in me that we will be assigning it with a transform component so public transform could call that fireball and um that fireball is gonna move like this so fireball that position is going to be equal to my position as the boss to transform that position and then we'll do a new vector3 and this one's going to be a little bit funky we're going to have to come out with the the mattes if you haven't done matt in a long time so we'll do a minus mat f using a cos operation on time.time and we'll multiply that by the fireball speed oh and on top of that we also need a distance so i'll do time distance and that's gonna be our x value distance is not uh declared so let's go ahead and do that put that equal to say 0.25 of course these are public we'll be able to modify them directly in the inspector so that would be our x now for the y it's going to be the same operation but instead of being a cross is going to be a sin and this one's going to be positive times the time time speed and time distance and finally for the z we'll just put a zero in here let's give this a try see what happens in the game see if we have the behavior we want so i'll be putting that on boss.cs it's already here wait until it compiles and we are going to first give it a decent amount of hp 10 is 10 is fine and um the rest is what we need down here is the fireball speed the distance and also the fireball so we have to create another object in here i will go ahead and find my enemy underscore one that is my little fireball i'll put it beneath my boss reset the position and it should be here as soon as i put it on my proper sorting layer which is um actor in this case that might be a little bit too big so maybe you want to put that on 0.6 like it was a second ago and yeah that could do the job right so having this done i will go ahead and i'm going to put the enemy underscore one under fireball and give this a try now this is going to crash because i'm not in the player scene but we'll see the mechanic happening right here on the right hand side so as you can see it does rotate around it um we're going to need to do a little bit more though maybe increment distance so it's something like this the fireball speed could also be increased so it goes really really fast it's really up to you at that point i'll leave mine on something like this we can have one that rotates a positive and also have another one that rotates negative so we could do that without any problem now i'm going to move the boss see what happens if i move this guy the fireball moves with me which is a behavior i wanted to have in the first place now if we wanted to we could actually turn these into lists so we could say public float here and firewood ball speed would be equal to say 2.5 for the first one and if we have a second fireball this one could be equal to minus 2.5 so we'd have one going clockwise in a one another one going um anti-clockwise and same thing here we'll need an array of fireballs with an s and we'll just do a for each transform t in fireballs and go ahead and run this into a forage statement so it would be t that position is equal to transform.position and then we would go here fireball speed would be um the index okay how do we get the index we are in a 4h statement so we're not going to get the index let me actually get rid of that really quickly turn my 4-h statement into a for statement a normal for statement as long as fireball dot length as long as i is smaller than fireball.length we'll take this put it back up and instead of calling it t we will be calling it fireball at the index i and we'll be using i here as well in fireball speed and just like this we're going to be able to have multiple fireball as many as you want in fact as long as you make sure that you have enough fire's ball speed to um to fit all the fireballs in here so if we have three make sure you also have three speeds and in terms of speed um i'll actually reset my values what do we have earlier we had 2.5 and minus 2.5 so that will do the job let's go ahead put two fireballs in here is everything else fine um the xp value could be something like 10 in here and we'll add another enemy and we'll put these in the two fields down here click on play we're gonna see the behavior as you can see they do rotate around the enemy actually they rotate around the boss and they just do their thing now there is one problem with this they don't do any damage so we're gonna make sure to fix that and also increment the distance here because that's not enough let's do 0.35 that could be perfect so i modified that 0.35 and i will go under enemy both of them and i'll add the enemy hitbox and just like this this boss and these enemy became a lot more dangerous the only problem we have at this moment is that yeah of course they have their enemy hitbox but they don't have the actual collider behind it so every single one of these are going to be using a collider let's go ahead and add a box collider 2d to this thing and the collider on this one might be a little bit too uh stretch so let me put that down like that that would be fine i believe that's with the fireball now the boss is also going to require a enemy hitbox and what we did with the enemy earlier is that we can have like an end box that's gonna serve as um what the player needs to it and another hitbox that is just the boss hitbox so we'll do the same exact thing i'll be copying it over from the small enemy so i'll just take this thing put it as a children of the boss and just reset the position of it now this is the collider i will be working with this is the collider that is going to hit the player so we're gonna have to make this one quite big maybe something like this could be big enough so if the player hits a tentacle at the top here he's not gonna get hurt he's just gonna get hurt if he enters that square we're currently building okay in terms of damage it's a boss so we want him to do a little bit more damage let's do like two the fireball they can do one damage we're fine with that but the boss we want him to do three even three damage maybe with a bigger push force of six okay now the boss itself is gonna require another box collider and this is the one we'll be hitting with our sword so let's go ahead and modify that we're gonna have to hit a little bit inside of the boss hitbox like the one that does damage and there we go we just created a new boss let's go ahead and try this out we should be killing him in two hits because we have the best sword at the moment let's go back under the main scene and run this game so we can see him on the on the scene view right here he's already oh he's way too fast but if i get hit by one of these let's see what happens oh they actually pass over me let's try let's try getting hit it's actually quite hard to get hit by this thing that i realized that oh there we go as you can see we did get bush by these little fireballs so there's gonna be some adjusting to be done now there's also gonna need some um a proper tag on this boss so if we go back on the bus real quick he needs to have the fighter tag and he needs to be on the actor layer i forgot about that um the fireball they don't need to be on the fighter layer because we can't kill them we don't want to kill them anyway so let's leave them like that and let's also make sure we bring them a little bit closer to the boss so let me go over here distance let's make that 0.3 okay i'm going to give this one more try and everything should be good to go after that all right so here we are i'm gonna go and attack this boss i did get hit i killed him got the 10xp and we are good right so um there is one more thing i'd like to adjust it's something i should have done before but on the mover script we inherit from mover most of the time um this one has protected float for the speed i'd like to make those public because the bus i thought was running at me quite fast and that was kind of annoying so we'll go ahead and modify that directly on him now that our speed floats are public so where the speed um he moves at one let's make him move at 0.5 and we also divide that by two for the y and just like this the boss should have a harder time catching up to us okay so this is actually a lot better it gives me some room to actually hit him and run away if i need to so i'll be ending this lesson right here in the next lesson we are going to do something about the whole player right now it's quite easy we can just one shot everything but if our player dies we need something to happen we need to have some kind of menu pop down and some kind of restart or you know wipe your save all right guys i will see you in the next lesson welcome back to what should be one of the final lesson for this course guys we are going to create a death menu for a little character so when he dies we're going to have a menu pop in my screen and just say well you're dead start over again at the main scene so there's a couple of things i'd like to do with this first off is we could actually delete the save of our player if he doesn't make this game kind of hardcore which i think would be fun well not really fun it would be like a dick move to do but hey that sounds like an interesting thing to do and also we gotta fit we actually gotta fix the size of this thing um on the boss we're going to swap the actual sprite so let's go and do that really quickly make sure we go on the sprite render and flip it on the x-axis so when it looks at us now and it runs towards us it's going to be fixed okay that out of the way we are going to create a def menu and i'll be putting that under um i think i'll be putting it under hud this way we don't destroy it just like we don't destroy anything beneath that right so we're going to go ahead and create a new oops right click on the hud we're going to create a new panel and in that panel we can call that def menu center it uh say the size could be 300 by 75 something really small actually a little bit bigger than that so we can actually read and put text on there so 400 by 150 would be great and on here i'll be making full alpha background like this and we will be typing in you are dead change the font put that in a red really aggressive color and make that bigger so i'll just make sure to stretch this container in all axes and here we go so some kind of uh menu like this that says you are dead and we are going to put a button that moves on back to the main scene so a new ui button and we'll just put that right below i'll call this button to main scene and on the text on top of it it's going to be something like wristband change the font maybe make it white and we're going to change the button color as well so of course you just put that on whatever you feel like putting it like it's all a matter of making your ui look good in the end i'm just being really really fast because i know you'll be having a different type of ui mine's gonna look something like this i will also scale down from my original size i put so maybe 300 is fine by 125 okay so we have everything we need at this point we're just going to need to scroll this thing in when it does happen oh and also something really quickly we'd have to do is to make sure we don't really see the background so much or at least we have something that covers the background even though it has no alpha it has no color uh just so we can't click on the menu and we don't have disk i'm setting going on right now so my def menu is actually going to become a def window kind of deal and i'll create something else on top of that so a ui panel again that's going to take the whole screen and that's going to be the dev menu and i'll put the dev window beneath it way we can have some kind of background maybe put that one black as well with more alpha so like 200 in alpha something really really dark okay so we have something like this for the def menu and we will be creating a animator on top of that so animator let's go ahead and right click on our artwork animation create a new animator controller def menu can't seem to type menu properly for some reason uh let's go ahead and drag and drop this thing on our depth menu we're going to open it up and start creating some new animations so pull down your animation window as well i'll put it here and we'll have to animate this thing so click on depth menu we are going to create our very first animation which is going to be hidden so def menu or actually let's do shown because it's already here so showing and what we're going to be doing in here is we're going to first before we do anything else add a canvas group to our depth menu this is going to allow us to control the interactable and also the block raycasts when it's showing we want the interactable to be on so notice that i just click on the record button i'm going to make sure this is a hundred percent alpha it is interactable and it blocks ray cass what else could be done so uh do we want to do the exact same thing as we did for the menu we could do that so we could say the def window starts say right about here so 400 in y and when we do the showing actually the showing would be zero and when we do the hidden it would be at 400 in y um i think that's actually all we have to do in showing so let's turn that off create a new animation call it def menu hiding and this one is totally the opposite so we'll want to go in here make sure the canvas group is on zero and alpha interactable is false block raycast is also false and we're going to go on the def window put that at 400. we don't see it right now but the window is going to scroll down to the center while the alpha is going up alright so that would be pretty much done for the animation now we'll have to do the animator we have it open right here then we are going to create some new parameter two triggers one called show and one called hide by default we want it to be hiding so i'll right click set as default layer and then i'll create a transition just to showing we don't even have to create one back because if the menu shows then you're dead and you have to click on that button the condition to go there is going to be of course shown and by saying that i just realized that we don't actually need the hide parameter but we'll just keep it in case we want to do something fancy in the future something like instead of respawning there we could do well watch this ad and we're going to give you 5 hp so you can go back in game and hopefully don't die again that is one way that people use to monetize their mobile game but also can happen on pc as well okay so hiding goes there the transition is show and then it's going to show okay so we're going to try this in the game we're going to need some triggers though first so when once we die we need a reference to def menu and then do def menu dot animator and set trigger show so we're going to go ahead and um under game manager we're going to create a reference to the dev menu actually in a reference the animator could be worthwhile as well so def menu animator and all we'll have to do is when the player dies so if we go under player.cs we're going to have the override for def somewhere oh actually we don't so let's go ahead and overwrite it protected override def and once we die we're gonna say game manager instance def menu dot set trigger and we're going to set the trigger called show now there's one more thing we want to do in here and it's the fact that we don't want the player to move if he's dead so we're actually going to block the update motor if he is then which means we're going to require a bullion saying is life and that's going to be true at the beginning and if we do die is the life is going to be equal to false and we can go in the fix a bit and say if we are alive then you can update the motor else you can't okay now um this should technically work by itself right now soon as we put the reference of the dev menu so let's go ahead and grab the def menu put it in here and give this a try game starts we didn't see it that's pretty good now it's gonna take a little while before i die because i have a lot of hp 15 hp so let's go here get hit by the bus couple of times try to get hit by these yeah that was a one so i got hit by the small one and i'm pretty much dead now the only problem is that i also get those these amount of text uh popping on my screen so we'll also do something about that the menu is here we can't click anywhere else which is what we wanted other than respawn which of course does nothing at the moment okay well let's actually fix that very very small bug we're going to override actually it's already overwritten but we're going to do something here on receive damage we're going to say if is not alive simply do a return this way we won't have the text pop up on our screen next up is going to be the respawn that is going to be under the game manager and we'll call the function respawn so def menu and respawn public void respawn oh and now something i realized in the wristband function since we're never deleting our menu it's still going to be showing your dead so we're going to have to go in the depth menu and make sure we do have the transition in between hiding and hiding and showing so make sure you have a transition from showing to hiding that has the condition hide this is only because we're not deleting the menu and we need it to move away once we respawn so when we respan start by setting the trigger for the depth menu to hide and then we will load up the scene so unity engine scene management scene manager load scene and we're gonna be loading the main scene okay now um let's actually give this a try there should be like a couple of bugs still we're gonna find them out as we test this out and what i just realized right now is that the local scale of this thing gets reset uh which is quite annoying and there's also like a floating weapon okay uh we'll fix all of these really really soon maybe in the next lesson but let's give this a try if we respawn we are back up here and we're still unable to move so very important that we tell the player that he he needs to be able to move again so under here on wrestband let's create something for the player let's say player dot respam and we'll go under player.cs make a public function again so public void respawn we're starting to get a little bit of stuff in here that's fairly cool and we will do a heal by max endpoint so we're going to heal our player completely and then we'll also do um what could we do next we could do all right we have to set is alive to true so is a life has to be said to true else we can't move anymore so that's gonna be something else and one more thing i'd like to do is also set the immune time uh last immune to now this way in case you're dying and you press on respawn um you're not gonna be pushed away as soon as you start the game maybe give it an example i'll give it an example first because i think that bug could have occurred before i think i saw it briefly but let's have a look at what happens if we don't put the immune time and we don't end up killing our target so let's go see the bus then he kills us like this and if we press on respawn yeah we start and we get pushed so we have to make sure that we also put the immune time on time that time this way our player is going to be immune when he presses on the button he's going to be immune for the same amount of time so maybe one second which is definitely going to give us enough time to load the new scene so we're going to try this again with the new code and like i said there's a couple of bugs still uh especially ordering of the chest ordering of a couple of things and okay so we've been we've been healed fully we didn't heat damage this time but we also been pushed so we have to reset the move vector as well the push vector so after the last immune we're going to say push direction is going to be equal to vector 3.0 and that should be pretty much it for the death menu was quite a little bit painful i'm not gonna lie um this was this was gonna cause a lot of bug and that should pretty much be it for the death menu so let's walk in this fight try to die we are stick to the to the boss right now so if he does manage to push us after hitting wristband we're going to feel it press and respawn we see the plus 7 hp that's our hp we get healed uh we could also hide that by simply not calling the el function we could just say well your max hit point is equal to while your hit point is equal to your max amount of hit point and then just fill in that bar but i like to see it the plus seven means you got revived i i kind of like that feeling so let's go ahead and walk into this as you could tell the box size of this thing not the box size but the local scale got changed and that is not cool there's also another cool little bug that i never thought would have happened but uh we're gonna we're gonna have to look into it and that bug is the following so if i just press on pause i go and i open up my player object look at the weapon right now and look at the collider so i'll just put it collider there and as we move away the collider is still here on the right hand side and i can i can actually kill the boss going back in there um let's try this again here he's gonna walk right into it and he just ate damage so it's something we also have to fix here welcome back to another lesson guys so we're going to be fixing those little bugs that make our game kind of weird when we play it such as this weapon we see over here in the on the right hand side in the scene view as soon as we're done hitting it we turn off the box collider but the box collider still exists which is uh you know quite quite a problem so i was thinking about turning it into something else uh maybe putting the size down to zero and making it unable to be being touched instead of putting it down um so i really wonder if that's gonna work or not i don't think it is because we might run into these error as i just did down there so there's a couple of solutions some of them are quite weird and i don't really want to take those um but what we could do is we could actually take this collider and just put it somewhere else in the map like completely give it a weird offset um this is a bug that i did not think would actually happen simply because while your collider is off technically it should not be there anymore as you can see it's supposed to be toggled off so why is it following us um so that's something i did not really want to have to deal with but i guess we are going to create some kind of way that instead of putting it instead of putting the collider offline like we do right now we are going to take it and actually hide it somewhere really really far like here we hide it over there on this side so we will be doing that in the animation under the weapon swing so i'm going to go ahead open up the animation window and we are going to go here and instead of doing the connect the collider enabled we're going to turn that off completely so delete that completely and we'll just play with the offset of that collider so let's actually anchor this somewhere go under the player see his weapon right now he's at the proper place we're going to go ahead and start recording put the offset on zero make sure this is recorded also i'll play around with the y offset as well and here it is now we're going to keep that all the way till the end and just before just before the actual end we're going to be setting a keyframe um again by clicking on this button at the top add a keyframe and this is going to add a keyframe for everything so the offset x and y as well that's fine um actually if you want to be clean we can delete the one for position and then just after on the last frame i'll be taking these and just putting somewhere crazy so maybe 300 in a y and that's a lot 300 in our scaling system is actually quite a lot actually i don't even i don't even know if i can see it but it is quite far away because if you just put it up by one you see that it goes up that much let's go ahead and do 300 we should not have a level that is bigger than that and then once we replay this animation it's going to go back to zero because the beginning frame is zero so technically you're never going to see that again okay so let's play this give it a look and i think that's gonna work out just fine um let's go ahead and do that in idle as well in idle we're going to make sure we disabled this last one this last property in our timeline and that one was just to turn off the collider so we're going to remove that and instead we're going to say well let's put the y-axis of this offset on 300 i actually don't want to mess around with x x is fine the way it is we can leave it on zero and just like this we should have fixed our very first bug now i know this is not the best way to do it but i really was not expecting to have such bug um happen to us so let's go ahead and see where is our collider if you have a look down here you can see it i have a look right now in the in the scene view you're gonna be able to see the collider and it just disappear after and it doesn't stick where we were so that's fairly cool so as you can see the collider does not stick here after if we just move around you're going to see collider moves away completely off screen we don't see it anymore okay so that should be fixing our very first bug the the second bug is gonna be the fact that this boss over here we're gonna have a look at the boss from the scene view and when he starts chasing us he's gonna shrink down in size and that is because we modify his local size so we don't want that to happen i'm going to try and reproduce the bug there we go that's fixed but yeah we have to do something about this little guy that actually changed size and that's something that could have happened to everybody because the way our code is made if we go over to the mover.cs you're going to be seeing that no matter what happens you're going to be put back on this vector and that's not something we'd like so what we'll do instead is we're going to create a private um private vector3 we can make it protected if you wish this one doesn't need to go anywhere so i'll just do a private vector3 call it original size and in the start i'll say original size is equal to transform local scale now what i'll be doing is the following so on the swap sprite direction i'll be saying if we go towards the right hand side we'll say original size and if we go towards the left we'll say new vector and we'll do original size that x times minus one and then original size that y and original size dot z so we can keep that for every single axis this way that bug should also be fixed again let's give it a try i miss my old weapon and this one should not shrink as you can see it keeps the full size and it just walks to us really amazing and i actually have a hard time winning this thing actually i've been i've been pushed back into the main scene okay so we have to defeat this little boy first let's go ahead and kill him also very tough good thing we leveled up we have more do we have more damage now um no we don't have more damage we just have more health so let's go ahead and do a little bit of a trick we're gonna go down grab this level our weapon then we're gonna have more damage defeat this boss i am being murdered right now there we go grand victory we're gonna go ill ourselves and is there any more bug yeah there is one more bug that is really annoying is the fact that you actually are behind the chest when you try to loot so that's definitely just an order problem so those chests we can just put them on a higher layer um so let's go ahead and have a look at what kind of player we can put them on so we're going to put a chess into the main scene put that over our player um and actually just change that like change the the uh sorting layer we know that actor goes over most of these things so let's go ahead and just add a sorting layer change the actor put it down there so it goes above the wall and the interactable stuff i think the actor has to be on top of that as well um making our interactable object beneath the player so just by doing this i think we'll be good to go other than that we should be pretty much ready to go to create a build and actually try this as a standalone there's one more thing though i'd like to do uh go back on depth menu real quick and turn off the has exit time i forgot to do that i realized that last time i died it took like point one second to get me my menu which is a very very small thing but it kind of annoyed me so i changed that and let's go ahead go under file build settings uh build for a pc in my case we'll be adding the dungeon scene i don't know why it's not there anymore let's put that in here and go ahead build and run this thing on my computer as a real.exe hopefully everything should be the same exact thing as we've been experimenting through the engine and here it is it asks us for screen resolution we know that our game is made for 800x600 i'm not going to put it in full screen because it's just going to look awful but we can put the graphic top hit play we have our game our standalone game and we can just move around this guy tells us hey welcome to the chorus hit the boxes i'm not going to hit the boxes and we just play our game the same exact way as we were playing it in the editor all that time a couple of tweaks could be done we can add some multiple enemies uh we can tweak the speed of that one that one is really really aggressive and change the xp he gives out 10 xp right now which is too much but you get the point this is the same exact game we play it inside of a real.exe so if you ever want to send this over to your friend it is quite simple all you have to do is go over to where you built it in my case i built it directly in in this in my project folder go ahead and take these two files send that over to your friend and he should be able to play your game and guys that is how we created this whole top down game i hope you enjoyed it i hope you learned a lot of things and i hope to see your game in the community chat you're also free to ask us question at any time of the day thank you so much for following this course guys i will be seeing you on udemy on discord or really anywhere where we pretty much um play around we make games all day i'll be seeing you guys there make sure you ask some questions make sure you interact show us your game we'd really like to see what you've made and if you've made a custom athletes that'd be even better and uh we're eager to see that so thank you very much for watching this again and i will be catching you in the next course
Info
Channel: Epitome
Views: 370,932
Rating: undefined out of 5
Keywords: Top Down RPG, Learn Unity Engine and C#, Learn Unity Engine, Creating a real top down RPG, FULL COURSE, c# unity tutorial, Moving and Manual collision Detection, Tilemap and Designing Dungeon, Interactive Objects and Inheritance, Saving Game State, Floating Text System, Top Down Combat System, Animator And Weapon Sing Animation, Character Menu And The New UI System, Polishing and Adding Content
Id: b8YUfee_pzc
Channel Id: undefined
Length: 465min 48sec (27948 seconds)
Published: Tue Mar 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.