Make A Game Like Pokemon in Unity | #14 - Party System

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

This is the video I think a lot of ppl were waiting for.

👍︎︎ 3 👤︎︎ u/ProudBlackMatt 📅︎︎ Jul 14 2020 🗫︎ replies

If you're new to this series, this a series where we'll create a Turn-Based RPG like Pokemon in unity using Design Patterns and Good Game Development Practices. I'd love hear what you think about it :)

Here is the entire playlist.

👍︎︎ 2 👤︎︎ u/GameDevExperiments 📅︎︎ Jul 14 2020 🗫︎ replies
Captions
hey everyone welcome to part 14 of the pokemon game series in unity so in this video we will implement a party system so instead of hardcoding the player pokemon we will be able to use a pokemon from our party and if that pokemon faints the next one in the party will be sent out special thanks to all my patreons for supporting me in this journey so you can support the making of the cds by becoming a patreon and get access to some cool rewards so let's get started so right now we are hard coding the player and enemy pokemon in our battle system so if you look at the battle unit script of the player unit or the enemy unit as you can see that we are hardcoding the pokemon and the level here so instead of this we need to set the pokemon dynamically so in our battle unit script let's remove the serialize field for pokemon base and level and instead of hard coding it we will pass the pokemon as a parameter while calling the setup function so i'll just assign the pokemon passed in the parameter so next we need to actually pass the pokemon while calling this function so so for that first we need to create a pokemon party so inside the scripts folder inside pokemon i'll create a new script called pokemon party and inside the script we need a list of pokemons i'll make it serialize field so that we can set it from the inspector so now let's attach the script onto our player game object but down here you can see that we have an error inside our battle system so our pokemon party script phone compile until we fix this error so let's double click on this and it will show us the error so it's because we are not passing the pokemon inside the setup function even though we even though we changed it here so let's just comment these two setup functions for now and we'll come back to this once we are done with our party system so now ut should compile the script and we can attach it to our player game object so here you can see that the list of pokemons are not visible even though we made that a serialized field inside the pokemon party so if we look inside the pokemon class we can see that pokemon base and level are not serialized fields so we can't use this short way of defining properties when we want to show it in the inspector so let's create separate private variables for this and i'll make it a serialized field so that it'll be shown in the inspector i'll also create one for the level now inside the property we just need to return the private variable so let's also do this for the level property and finally we need to add system dot serializable attribute on top of our pokemon class because classes will only be shown in the inspector if we use this attribute so we do have an error here in the constructor but we actually don't need to assign this from the constructor anymore since we'll be doing it from the inspector so let's remove these lines and the constructor will not be called anymore because we'll be creating objects of the pokemon class from the inspector itself so which means all this initialization code will not be run so instead of doing this from the constructor we'll do it inside a function called init which stands for initialization so we can add all our initialization code inside here so now if we go back to unity you can see that the list of pokemons has appeared in the inspector so let's say i have two pokemons initially in my party and for the first one i'll choose charmander of level seven and for the next one i'll choose a bulbasaur of level three so these will be the pokemons in our hand when we start the game so now when starting a battle we can choose one of the pokemon from this list as the player pokemon instead of just hardcoding it so next what can we do about the enemy pokemon in the battle so in pokemon games each area will have a list of wild pokemons and when the player walks to the grass we should choose the wild pokemon in that area randomly so we need a script to store all the wild pokemons in an area so inside scripts i'll just create a new folder called gameplay and inside this folder i'll create a new script called map area so this script will store all the wild pokemons in this area so we need a list of pokemons and i'll call it file pokemons and i'll also create a public function which will return a random wild pokemon and i'll just return by pokemons off i just need to pass a random index here so i'll use random.range of 0 and the size of the list which we can get from the count property so in the future we will write better algorithms that will return random pokemons based on the rarity but for now i want to focus on the party system and this should work fine so let's go back to unity and let's assign the map area script to our grid you can actually assign this to whichever game object you want and let's say there can be two different while pokemons in this region so first one is a bulbasaur of level five and the second one will be a bulbasaur of level let's say seven i guess it's time i need to add more pokemons all i have is a bulbasaur and a charmander so now even though we are creating the pokemons from map area and the player party we are not calling the function to initialize it so remember we created a function so we just have to call this function for that so inside my pokemon party in start function i'll loop through all the pokemons and initialize each one of them and in case of the wild pokemons we just have to initialize them in this function because they are only relevant in the battle so first i'll store this in a variable and then initialize it before actually returning it so now in the battle system we need to pass the player party and the wild pokemon while calling the start battle function so let's create a parameter for the player party and one for the while pokemon and let's just show that in private variables and let's assign the parameters to our variables so we'll have to use this keyword since the name of the parameter and our variables are same so i'll say this dot player party equal to player party and also do the same for the wild pokemon so now since we have the player and the file pokemon we can pass them into the setup function of the battle unit so to the setup function of the enemy unit i'll pass the wild pokemon and for the player unit we can pass the entire party we just we will have to choose a pokemon from the party so what we'll do is we pass the first pokemon in the party that is not fainted so let's create a function inside the player party in order to return that we'll create a public function called get healthy pokemon i named it healthy pokemon because we should not return any pokemon that's fainted so how can we find a healthy pokemon one ways we can use a for loop to loop through all the pokemons in the party and check if the hp is greater than zero to make sure it is healthy so yeah for loop would work fine but let me show you an easier way of doing it so we'll use link instead of for loop so we can say pokemons dot there so you can see that their function does not exist right now this is because we have to import the name space for link so i'll just use control dot and import link so now to the wave function we need to pass a condition to the condition we want to check is if the hp is greater than zero so we can pass it like x arrow x dot hp greater than zero so if you have never used link before the where function will loop through the list of pokemons we have and it will return the list of pokemons which satisfies this condition so this line of code will return all the pokemons that are not fainted in our party but we don't need all the pokemons we just need the first one that is not painted so for that i'll say dot first or default and we actually need to return this so now this function will return the first pokemon in our party that is not painted and in case if all of the pokemons in our party are painted then this code will return null so that's how this works so let's actually call this inside our battle system so inside play unit dot setup i'll call player party dot get healthy pokemon so next we'll go to our game controller where our start battle function is called we'll have an error because we are not passing the player party and the file pokemon so i can get the player party from the player controller since both of them are confidence of the player game object so i can say player controller dot get component of player party of a pokemon party so this will return the pokemon party component on the player game object and to get the vile pokemon first we need to grab a reference to the map area so i'll do it by find objective type map area which will return the game object with the map area and i'll use the get component to actually get the script and finally i'll call the get random while pokemon function which will return a random white pokemon so let's pass this into our start battle function and that should be it so now if we start a battle the first pokemon from our party will be selected as the player pokemon and one of these pokemons will be selected as the enemy pokemon so let's test that if i walk through the class okay you can see that level seven charmander was the first pokemon in my party and it was set as the player pokemon and a bulbasaur of level five was set as the enemy pokemon so if we fight the wild pokemon so i lost some hp in the battle and now if i try to start another battle you can see that my player pokemon starts with the hp that was left from the previous battle so let's look at what happens when the player pokemon faints okay it should faint in this attack so now we went back to the free roam state even though we should have been able to use our second pokemon we will do that in a moment but let me show you something else if we start a new battle then we will send out the second pokemon in the party since our first pokemon has fainted so that's working just as how we want it so next let's implement the logic to send out the next pokemon in the party when the first pokemon faints so in our battle system inside enemy move if the player pokemon faints we're just calling uh on battle hour to finish the battle so instead of doing that first we need to check if there is any other healthy pokemon in the party so we can do that by using player party dot get healthy pokemon and i'll store the pokemon in a variable called next pokemon so if next pokemon is not equal to knowledge which means there is actually a healthy pokemon in our party then we should send out that pokemon for the battle and otherwise if all of our pokemons have fainted then we'll discard on battle over and return false indicating that the player lost the battle so in here we have to write the code to send out the next pokemon so it's kind of like the code in the setup battle so let me just copy paste that so we're just calling setup on the battle unit and setting the data on the hut setting the names of the move in the dialog box and all that so we don't need to do this for the enemy pokemon since we are only changing the player pokemon and for the pokemon we should use the next pokemon that we got from here let me just change that everywhere and for dialog i'll just say go and the name of the pokemon and finally we should go to the player action state where the player can choose to fight or run so let's go back to unity and test this so let me start a battle let me keep attacking until my play pokemon faints so i need to start another battle and do this till my player pokemon faints okay so my first pokemon fainted and we did send out the second pokemon in the party so we can also try fighting with our second pokemon all right so everything work just as we wanted so i'll stop the video here and in the next video we will look at how to create a party selection screen and let the player switch the pokemons in between a battle so before you go make sure to leave a like on the video and subscribe to the channel if you haven't already and i'll see you in the next video
Info
Channel: Game Dev Experiments
Views: 7,127
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, unity turn based battle system, turn based battle system in unity
Id: CqdjjJcwsvw
Channel Id: undefined
Length: 18min 40sec (1120 seconds)
Published: Tue Jul 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.