Make A Game Like Pokemon in Unity | #22 - Volatile Statuses & Showing Pokemon's Status in HUD

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome to part 22 of the pokemon game series in unity so in this video we will show the pokemon's status condition in the ui and we will also implement volatile statuses like confusion that will only last for the duration of the battle special thanks to all my patreons for making the series possible by becoming a patreon you can support me in the making of the series and get some cool rewards like access to the complete project files of the series so let's start the video alright so first let's fix some issues that we currently have so right now if a pokemon has a status condition we will still be able to set another status condition to it but that shouldn't be possible right so inside our set status function when we are trying to set a status i'll check if status is not null and if there is already a status then i'll just return instead of setting the new status okay so next i also want to fix a small mistake that we made in our max hp calculation formula so in this formula i also need to add the level at the end okay so this mistake was something that i recently found so next i want to show the status condition of the pokemon in the hut so let me just enable my battle system okay so i want to add a text in the hud that will show the status condition of the pokemon if it has any so first i'm going to turn her into prefab so we don't have to make changes to both the player and the enemy hud right so inside the game folder we have a ui folder where we can keep the ui prefabs so i'll just drag and drop the player hud into the ui folder and turn it into a prefab and i'll just rename this to hud okay so next i'll just delete the enemy hud game object and drag our hud prefab into the battle canvas okay so let me just keep it just below the player hud and i'll rename this to enemy heard all right so let me just change its position also okay so that looks fine and in our enemy unit game object you can see that heart is missing since we deleted the old game object so let me just drag and drop our new enemy hud into the hud slot okay so now we can add our status text into the hud prefab so i'll open up the hud prefab by double clicking on it and i'll make php bar a little smaller to give some space for the status text and i'll duplicate the level text and create the status text okay and let me just change its position and i want to reduce the font size to 28 and i'll make the alignment center both horizontally and vertically and i'll just change the text to something like poison let me just rearrange this okay that looks okay to me and we can also give the text any color we want okay but since each status is going to have a different color we will be setting it from the script all right so let me go out of the prefab and both our enemy hud and player hud should have the status text all right so next let's modify our battle heart script so let me open the battlehead script and first we need a reference to the status text right and then i'll create a function called set status text okay so inside this function we need to check if pokemon.status is not so if it's not then we can just set the status text to an empty string right okay and otherwise we have to set the id of the pokemon status condition in the status text so right now we don't have an id inside the condition class so if i say pokemon.status dot id you can see we don't have a property for that we only have name right and right now we only have the id as a key in the dictionary but we need to be able to access it from inside the condition class so for that inside the condition class i'll also create a reference to the id okay and then in the condition db script we can also set the id from here but it would be redundant and prompt mistake to set something two times right so instead i'll create an init function inside our conditions db to initialize everything so this function should also be a static function and i'll just call it init and inside this function i will loop through all the elements in the conditions dictionary so remember inside the dictionary we have both a key and a value and not just a value right so basically we have a key value pair so i will write it as kvp per shot and i want to loop through all the key value pairs so in the dictionary the key is the condition id and value is actually the reference to the condition so let me just store them into variables just for clarity okay and we can just assign the id inside the condition class from here okay so condition id will be automatically set for all our conditions so we are not doing this just to show it in the heart it's very important to have the id inside our condition class because in the future we will we will need it in a lot of different places so next we need to call this init function when the game starts right so i'll call it inside our game controller script okay so inside game control script i also create an awake function and in here i'll just call conditions db dot init okay so in the future we are going to have a lot of different things inside our init function but for now let's just set the id all right so let's go back to our battle hud script and now we can just say status dot id to get the id of the status condition and since it's an enum we need to convert it into string and i'll also use two upper to change it to uppercase okay so we are done with our set status function and we can just call this function to update the status in the hud so initially from the set data function i'll call set status text so that whenever we set the pokemon's data to heart we will also set the status and then we also have to set it every time the status of the pokemon changes right so for that inside the pokemon script i'll create an event called on status changed so i need to import the system namespace but i can also say system.action so that we don't have to import it okay so we need to call the on status change function whenever a status is set or cured right so inside our set status function let's call the on status change event okay so let's also call it inside our qr status function all right so now inside our battle hud i will assign the status text function to the on status change event of the pokemon okay so i'll say pokemon dot on status change and i'll assign our set status function okay so now whenever the status is changed this function will also be called so next i also want to set different colors for different statuses so for that i'll create a color variable for each one of the statuses so for poison i'll say poison color and similarly i'll create one for all the statuses okay so we also have to change statistics.color when changing the text so i'll actually store all these colors in a dictionary so that so that we can avoid lots of if else statements so i'll create a dictionary and the key is going to be condition id and the value is going to be color and i'll call it status colors and let's just initialize it inside our set data function okay so for poison i'm going to assign the poison color and similarly we can do it for all the other statuses okay so now all we have to do is after setting the text we'll say status text dot color equal to status colors and for the condition id we'll pass pokemon.status dot id okay so let's go back to unity and let me open up the hud prefab and now inside the battlehead script we will have a color for each one of the statuses so let me set them okay so we also need to make sure that the alpha is 100 otherwise it's going to be transparent okay so similarly i'll set all the colors okay so i'm done setting all the colors so let's save it and go back out of the prefab okay so let's test the game and see if it's working all right i have to disable my battle system let's test again okay let me start a battle all right so we have another reference error so let's go inside our hud prefab and yeah i forgot to assign the status text so let me just drag and drop that and this time hopefully it should work okay so if i use thunder wave bulbasaur should be paralyzed and you can see that the status text over here change okay so let me try continuing the battle all right so bubbles are used to poison powder and you can see that pikachu got poisoned right okay so we are done with showing the status condition in the hud all right so next let's implement volatile statuses so volatile statuses are statuses like confusion that bears off once the battle is over so in our pokemon class i'll also create a variable to store the volatile status and i'll also create one to store the volatile status time okay so next i need to create a function to set volatile status and cure it all right so i'll just copy the set status function and change it to set volatile status so set volatile status is going to be similar to set status but we need to change all the status variables into volatile status so i'll just use ctrl alt and add multiple cursors and change all of them to volatile status and we don't need to call on status change event because our volatile status doesn't need to be shown in the hud so i'll just remove that and let me also copy qr status and create cure volatile status function okay so in here i'll set volatile status to order and i don't have to call on status change okay so we have functions to set and cure volatile status so the main difference in volatile status is that they will only last until the battle is over so once the battle is over we can just set it to not so in our own battle over function i'll just set volatile status to know and next we also need to call the events of volatile statuses in on before move and on after turn so let's do that i'll say volatile status dot on after turn and in on before move what i'll do is i'll create a boolean variable called can perform move and i set it to true by default and i'll return that at the end of the function so now since we also need to run on before mo on volatile statuses we can't simply return from here so instead what i'll do is check if on before move returns false and if that's the case then i'll set can perform move to false okay so we also need to do this for the volatile statuses right so i'll just copy paste and rename the variable okay so now in the on buffer mode if either the status or the volatile status has an on before move action then we'll execute that and if it returns false then this function will also return false so next let's implement confusion which is a volatile status so in the conditions db i'll add confusion to the condition idenum and confusion is going to be very similar to sleep since it lasts for a certain number of turns and its functionality is executed inside onbuffer mode so let's implement that so i'll just copy paste the implementation of confusion instead of writing it from scratch so that we can save time okay so this is the implementation of confusion so you can see that just like with sleep confusion will last for certain number of turns and we are actually setting that from the onstart function so one thing to note is that we are setting and modifying the volatile status time and not the status time since confusion is a volatile status condition and also once the volatile status time is over we are curing the volatile status so the one difference between confusion and sleep is that when a pokemon is sleep it will never be able to perform the move right but in case of condition there is 50 chance that it can perform the ball so here we just create a random number between 1 and 2 and if that's equal to 1 we'll just return true indicating the pokemon can perform the move and if the pokemon wasn't able to perform the ball then it'll take a damage due to its confusion right so this part is the only difference between the confusion and sleep status okay so we have implemented a volatile status so now let's modify moves so that they can also cause volatile statuses so inside our move base script right now a move can cause stat boosting and a status condition so we also need to add a volatile status here so i'll duplicate this and rename it to volatile status okay so let me also create a property to expose it all right so now in our battle system script inside run move fx we need to set the volatile status if it's not none okay so let me just copy paste the code for the status condition and just modify it so we need to check if volatile status is not none and we need to call set volatile status instead and finally we need to pass fx dot volatile status okay so now if the move has a volatile status we will set that to the pokemon so that's it you're done with the implementation of volatile status conditions but one thing i forgot to do while implementing the status conditions is that inside the init function of our pokemon class we need to reset all the values of the pokemon right so we also need to set the status to null and we don't have to set the volatile status because it will automatically be set when the battle is over but just for safety i'll also set the volatile status in order okay so now let's create a move that can cause confusion and test it out so in my moves folder i'll duplicate poisson powder and rename it to supersonic okay so let me also change the name and i'll change the type to normal and now inside of the fx we also have a volatile status so supersonic should not set any status condition so i'll change that to none and for the volatile status condition i'll set confusion right so when we use supersonic the enemy pokemon will be confused okay so let's give supersonic to some pokemon i'll give it to bulbasaur alright so let's try testing the game okay so i'll just use more and wait for bulbasaur to use supersonic okay so bulbasaur used supersonic and you can see that pikachu has been confused all right so let me try to continue the battle so yeah you can see pikachu is confused and it wasn't able to perform the move and also it was hurt due to confusion but our hp didn't get reduced so that's an issue that we need to fix so let's look inside the run mode in our battle system so yeah here you can see that after executing on before move we are only showing the status changes but not updating hp that's because until now we didn't have any statuses that could reduce the hp in on the firmware so let's actually call the update hp function to do that so after show status changes i'll call source unit dot hud dot update hp okay so this should fix the problem all right so let's test the game again so i'll just use move and wait for purple sword to use supersonic okay so bulbasaur used supersonic and you can see that pikachu is confused and from the console we know that it will be confused for four moves so yeah let's try continuing the battle okay okay i was able to use some more two times even though i was confused so let's try again yeah you can see this turn i was not able to use the move and i was hurt due to the confusion so let's try again so yeah even this turn i wasn't able to do the move and was heard during confusion so yeah four turns are over and we should be able to kick out of the confusion in the next turn so let's test that so yeah you can see pikachu kicked out of confusion so it's working like we expected and yeah bulbasaur used supersonic again and pikachu is again confused okay so let me just finish this battle so even though pikachu was confused at the end of the battle it won't be confused when you start a new battle since we are clearing the volatile status at the end of fd battle right so we are done with the implementation of volatile statuses i'll stop the video here if you think this videos are helpful please leave a like on the video and subscribe to my channel to help it grow so i'll see you in the next video
Info
Channel: Game Dev Experiments
Views: 3,595
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: 3t1DoaJKBsI
Channel Id: undefined
Length: 24min 25sec (1465 seconds)
Published: Sat Sep 12 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.