Make A Game Like Pokemon in Unity | #67 - Story Items

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome to part 67 of my pokemon game series in your d so in this video we'll create story items so story items can be used to take the story forward by using dialogues and cutscenes so we haven't implemented cutscenes yet so for now we'll use story items to trigger dialogues so let me show you how it works so if i try to go out of the scene you can see that it shows a dialogue saying it's not safe to go out there without a pokemon so basically we have a triggerable object in these two tiles that is triggering a dialogue so story items will be pretty useful when we start implementing our quest system so let's look at how to implement them special thanks to all my patreons for making the series possible by becoming a patreon you can support me and get access to the complete project files of the series the project files also contain some advanced features that are not covered on youtube so let's start the video so first i'll go to the hometown scene and here i'll create a new game object called story item all right so let me reset its position and i'll place it over here okay so next i'll add a box clutter to it okay so let me add a box color to 2d and i'll change its x size to since you want to cover two tiles so now let me just reposition it to the exact center okay so next i'll create a script for the story item so in scripts inside the gameplay folder i'll create a new script called story item all right so let me get rid of all the default code so the story item will be a player triggerable object right so when the player steps on it it should trigger an action like dialogue or cutscene so i'll make this class implement the i player trigger interface and if we implement that then we should also implement the on player triggered function okay so let me implement that also so inside this function i'll just write a deeper clock to test if this is working so if you don't remember how the player triggerable system was implemented i'll link the video in which it was implemented in the cards okay so basically we used the same triggerable system for implementing other objects like long grass and bottles and all okay so we'll implement the story item in the same way so in order for this to work we need to add the story item to a layer and we need to mark that layer as a triggerable layer right so i'll create a new layer called triggers okay in the future we can put all the triggerable objects in this layer instead of having a separate layer for each one of them okay so let me set the layer of this jewelry item to triggers and to this object i'll add the story item script that we just created so next we need to assign this layer in our game layers script so let me open up the game layer script so here we have a reference to all the layers in the game so let me add a variable for the triggers layer okay and then i'll make sure to return it in the triggerable layers property okay so now let's go to unity and assign the triggers layer in the game layer script so game players is in the essential objects so let me open the essential objects prefab and we have game layers in the game control object so here i'll assign the triggers layer and now the story item should be triggered when the player walks on top of it okay so let's test it all right so here you can see it's printing the story item is working so that means the on player triggered function is being called so next instead of just printing this we want to show a dialogue right so first i'll create a variable to store the dialog all right and now inside the on player triggered function we can call dialog manager dot instance dot show dialog to show our dialog okay so since this is scorpion i'll put it inside start corroding function all right so let's go to unity and assign a dialogue to the story item okay so i'll say something like it's not safe to go out there without a pokemon all right so let's go and test this okay so dialogue is working but the player is still animating right so when this happens we also need the player to stop animating so if you look at the implementation of long grass or portal you can see that we are setting is moving to false to stop the player from animating so i'll do the same from story item also okay so let's just now i'll just restart the game all right so now it's not animating and it's showing the dialogue when the player steps on it okay so next there is one issue that we need to fix so if i'm standing on a story item and then if i move to the style you can see that it shows the dialogue again right but we don't want that if the player is already on a story item then we should not trigger it again if the player moves to another tile with the same story item okay so for story items we don't want to trigger them repeatedly but for some triggerable objects we do want them to trigger repeatedly try it for example for long grass we want to keep triggering when the player moves over the same trigger right so let's look at how to handle that so what i'll do is in the i player triggerable interface i'll create a new property called trigger repeatedly okay so when we create a property like this inside an interface we'll have to implement that property in all the classes that implement the interface right so here in long grass and portal and story item you can see that we are having narrow because we are not implementing the sugar repeatedly property right so let's go ahead and implement that in all the classes so i'll implement it in the story item first okay so let me just move this below the on player triggered function and in the case of story item we don't want to trigger repeatedly right so i'll return false okay so next for the long grass we don't want it to trigger repeatedly so i'll return true for this okay so next for the portal we don't really want it to trigger repeatedly so i'll set it to false by the way even if it was true it wouldn't be a problem because as soon as we step on the portal we'll block the player from moving and we'll switch the scene right so it doesn't really matter but i'll just set it to false okay so next we have two other classes that implement the player triggerable interface so we have location portal so here also i'll return false for the trigger repeatedly property and finally we have trainer fob all right so here also i'll return false okay so let me just close all the scripts that we don't need and now we should check the value of this property to determine whether we should trigger it or not okay so we are triggering this from the player controller right so in the player controller inside the on move over function when the player moves to a new tile we are creating an overlap circle there and you're checking if there are any triggerable objects in that tile right so here what we need to do is if the player moved to a new tile which has the same triggerable object and if that triggerable object has trigger repeatedly set to false then we should not trigger this function again right so first we need to keep track of the trigger in which the player is currently in so for that i'll create a variable card currently in trigger and if we find a detectable object on the tile then i'll set currently in trigger to the triggerable object that we found and when we find a triggerable we should check if it is equal to the trigger that we are currently in and its trigger repeatedly value is false right so if we moved over the same trigger and the trigger repeatedly set to false then we don't want to trigger this function and we can just break right and finally we also have to clear the currently in trigger variable when we go out of the current trigger right so at the end of this function i'll check if colliders dot count is equal to zero so that means there isn't any triggerable object on that tile right so if the count is equal to zero or if there is a triggerable object on the tile but if it's not same as the current one even then we can we can clear the currently in trigger variable okay so i'll also check if the triggerable okay so since the triggerable variable is defined inside the for loop we don't have access to it out here so i'll just define it above the for loop okay i think i made a typo here let me just fix that so yeah now we can access the trigger object outside the loop and here i'll check if the triggerable object is not equal to the current one okay so here we have an error because this variable might be unassigned if this loop doesn't run right so let me just set it to normal by default okay so if this is the case then we can just clear the currently in trigger variable all right so let's go to unity and test if this is working so let me go step on the story item and now if i move to this style you can see that it's not triggering again when we move over it okay but if we come out and then go back it'll trigger again all right so that's working correctly the story item is not triggering repeatedly but let's also go test the long grass so in the case of long grass it should trigger repeatedly and it is actually triggering but we are having this error because we are not testing it from the gameplay scene we are just testing the individual scene right so let's go to the gameplay scene and test that to make sure we don't have any issues okay so if i walk over the long grass it should keep triggering repeatedly okay so it's just that so yeah it's working right but if we step on the story item you can see that it'll only trigger once and it won't trigger unless you come out and work on it again okay so i'll stop the video here and in the next video we'll start working on our quest system so we'll use the story item to block the player from moving out of the scene and we'll let the player go once he completes a quest okay so before you leave please leave a like on the video and consider subscribing to my channel that'll really help me out so i'll see you in the next video
Info
Channel: Game Dev Experiments
Views: 867
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 story system, unity story game
Id: pkhvE0VFSI8
Channel Id: undefined
Length: 17min 21sec (1041 seconds)
Published: Sun Sep 26 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.