Make A Game Like Pokemon in Unity | #5 - Creating Pokemons Using Scriptable Objects

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome to part 5 of the Pokemon game series nudee so in this video we will look at how to use comfortable objects to store the data of pokemons so scriptable objects are data containers in unity that lets you store large amounts of data efficiently this is early when you're making a game with lots of data like an RPG so first we need to create a class called Pokemon Base so inside scripts I'll create a folder called pokemons and here I'll create the Pokemon based script so this script will contain all the basic details of a Pokemon like name type base stats and all that so let's open this initials for you okay so first we need to change the monobehaviour to scriptable object so next we create the variable let's destroy the data of the pokemons so we need a name for the Pokemon so inside scriptable objects I like to use serialized fields instead of making my variables public let's choose to serialize field attribute so the reason behind this is because we need to use this variable outside this class so in object-oriented programming it's bad practice to create public variables and Houston directly outside the class instead we need to expose these variables by using functions or properties we look into more of that later next I need available for description I also make this a text area so that we have some space to type in the description next we'll create variables for our friend and back sprites so we need both front and back straight of Pokemon in the battle system so next we need available for the type of the Pokemon so for that I'm going to choose enums so first let's create an enum called Pokemon type here we can specify all the types that we want in our game like normal firewater know that so let me just copy paste all the type the same time and I'll actually make the first type as none okay so now let's create a variable for Pokemon type Pokemon can have two types so since we used enums here you'll get a really nice picker in the UI which you'll see when we start creating our pokemons so okay so now we need variables for each of our base stats so these are the base stats that a pokemon has so we have max HP attack defense special attack special defense and speed okay so now you have scriptable object but we need a way to create instances of c scriptable object for that we can just add an attribute called create asset menu on the top of our class here we have to pass a file name and a menu knee we will have a new menu with its name which we can use to add new pokemons so if we go back to unity and right-click on our project window in create you can see that we have a new menu here called Pokemon and inside that you have an option to create a new pokemon that's what we specified here so I'll create a folder called game and I'll show all the prefabs and reputable objects in this folder so in here we will create another folder called resources it's a good idea to put all your scriptural object inside a folder called resources because later on you might need to load all the scriptural objects we have during the runtime so if you name your folder resources unity will let you load all the assets inside it given in runtime so in here I'll create another folder called pokemons and this is very bad or pokemons so let's add one Pokemon create new Pokemon and I'll call this purpose all so in the inspector you can see all the variables that we created inside the script of the object let's just fill this so we'll front and back sprite I'll just bring in some new sprites you create a folder called Pokemon and I'll I'll add some new sprites so inside the front folder you have all the front sprites and inside the back folder we have all the backs rights let's go back to the Pokemon meat is added as here I'll choose the sprite here you can see that since we used enums we have a really good really nice picker for selecting our type so those are the types and finally you can find all these base stats on a site called Volvo vidya so this is like a biggie for pokemon and and has everything from fights to all the formulas that are used in the game so i'm going to fill this so next I'll add one more Pokemon so on stats that you have you are base stats the actual step of a bookmark that's you or another trainer own will depend upon its level so a level 10 Charmander that will have much better stats than a level 5 Charmander so let's create another script called Pokemon so in this script we will calculate all the values that are specific to a level so we don't need to dry up from monobehaviour so of waka mantras is going to be plain C sharp class so in the Pokemon class first we need a reference to be Pokemon base class so we have access to all the basic details let's create available for that I can't use base as the variable name since that's a keyboard so I'll just add an underscore at the beginning next we need a variable for the level so with these two we can translate all the other stats for the Bachmann so since this is a plain C shop class we will have to assign this variable its from the constructor so the constructor will take these two parameters and assign to the two our variable so now we need a Bey to access all the data inside the Pokemon base class so earlier I told you that a good way of doing this is to expose these variables by using a function of or a property instead of making it public and using it directly so let's look at how we can do that then you can either expose this by using a function like this or you can use a cool facial in C shop called properties so for the properties we will use the same name of the variable but we will make the first letter capital so here you can see that n is capital e so inside the property you need to define a getter so a getter is like a function that will be called when we some code is trying to get the values of the property so in our Gator we just need to return the value of the name variable just like we did in the function about so these are two different ways to expose a private variable outside the class the cool thing about properties is that it lets you use this just like you use the variable but behind the scenes it's working by calling a function so if I want to use this inside the pokemon class all I have to do is call base dot name so this is just like using available so I prefer using properties instead of function so let's remove the function so let's create a property for the description so we need to specify which variable should be returned and trying to get the property so we need to create a property for each of these variables so I'll just copy bases to save time okay so now we have property for each one of them now in the Pokemon class being me to calculate the stats of the Pokemon at the current level so again we'll use properties here so let's create property for attack and in the getter we need to use the base attack and the level to calculate the actual at that stat so this is the formula used to calculate a stat from the base stat and level so we just wanna apply base that with the level divided by 100 and use the float to any function to remove the decimal point and finally add 5 to it okay so this is the formula that Pokemon games uses so I'll create properties to calculate all the other stats and just copy/paste them to save time so we use the same formula to calculate all the other stats the one thing to note here is that max HP it's a little different instead of adding 5 at the end we add 10 so you can read more about these formulas in Borba pedia so you might be wondering from where we will use this pokemon class so this is all makes sense when we start developing our battle system okay so I'll stop the video here and in the next video we will look at how to architect the moves of the Pokemon so if you think these videos are help please make sure to hit that subscribe button so I'll see you in the next video
Info
Channel: Game Dev Experiments
Views: 19,858
Rating: undefined out of 5
Keywords: make a game like pokemon in unity, how to make a game like pokemon in unity, make pokemon in unity, make pokemon game in unity, how to make pokemon game in unity, make a pokemon game in unity, unity pokemon game tutorial
Id: x8B_eXfcj6U
Channel Id: undefined
Length: 13min 2sec (782 seconds)
Published: Wed Jun 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.