QUESTING SYSTEM in Unity!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we'll go on a quest to make the best questing system the world has ever seen or at least a working one but first this video is sponsored by a skill share skill shares an online learning community with more than 25,000 quality classes on game development tech and more if for example you're making a 2-d game you can check out this really cool course on how to make 2d video game art this will teach you how to make characters animations backgrounds and all in all how to make custom graphics for your game Skillshare is the perfect platform to keep learning and thriving and a premium skill share membership gives you unlimited access to all classes for less than $10 a month join more than 7 million other creators by simply clicking the link in the description and the first 500 people will receive their first two months for free also I am super excited to announce that the community is hosting a nother practice game jam the gem will start on February 16th and ends a week later on February the 23rd the theme will be announced when the gem starts I encourage all of you to go join now everything is hosted on itch and I'll have a link in the description to where you can read more and join the event and if you've never participated in a jam before I really cannot recommend it enough it's a great way to challenge yourself in a completely stress-free environment after all game jams all about having fun I'll definitely be participating myself and we're also planning to make a video about our favorite entries once the jam is over I recommend visiting the game jam channel on our discord where people are going to be talking about the event and posting progress updates as we go along there's of course a link for that in the description as well now christening systems are one of those mechanics that vary a lot depending on the game both in terms of how you find them what you should do to complete them and also what rewards you get from doing so however I've gone it and created a really simple game that we will use as an example to build a questing system on top of NL of course make sure to show you how you can go about implementing it in your own game with that said let's start questing greetings traveler so as you can see I've gone ahead and created a simple example scene here we have a canvas with a player window that is currently displaying information about our player we have the health experience some gold and the player has two action you can either fight or he can try to pick up a quest to represent the player I have an empty object with a player script and as you can see we have the health experience and gold here if we open up the player script we can see how I've implemented this it's just three basic public int and then we also have this function for going into battle this is called whenever you press the fight button on the UI and it's simply going to subtract one health because we probably lost some health in the fight give us a tiny bit of experience and a tiny bit of gold that's really all there is to the game right now if we go ahead and play you can see that it compressed this fight button and the health is gonna go down and the experience end code is gonna go up a tiny bit however if I hit the quest button nothing happens so now it's up to us to create the questing system also the UI that I'm using is from the ultimate game UI pack from the unity asset store if you want to pick it up for yourself of course have a link to where you can get it in the description now the first thing that we want to do for a questing system is to define what a quest is I've gone ahead and created some UI for this again this is just completely placeholder UI there's no scripting involved here so my window basically has room for a quest title a description of the quest some kind of experience reward a gold reward and a button to accept the quest so let's try and implement these parameters through script we'll go to the project create a new C subscript and let's call it quest let's double click it to open it up in Visual Studio and let's go ahead and remove the two functions and we also don't want it to derive from monobehaviour so we'll go ahead and remove that as well now the first thing that we're going to need is a string with the title so we'll create a public string with the title of the quest also create a public string with the description we create a public int for the experience reward and another public in for the gold reward again what you want to have here completely depends on your game you can fill in extra variables or remove some if you want it's completely up to you we also need a variable to determine whether this quest is currently actives so let's go to the top here and create a public bowl called is active and that's all we'll do for the quest at the moment so let's save that and hit back into unity and the next thing that we want is to have some kind of way for the player to get the quest and this is of course again going to depend on your game in our case we are just gonna press the quest button and we are going to get a quest however in many games there are NPCs that you need to talk to in order to get quests or maybe even items that you need to find that will set you on new quests so how you want to trigger this is completely up to you I'm gonna go ahead and create an empty object which is going to be our quest giver let's go ahead and create a quest giver script on this object let's double click it to open it up in visual studio again we'll remove the two functions here we do want this to derive from monobehaviour and first of all this quest giver needs a quest to give away so we'll create a public quest and here we're referencing the script that we just created so the quest is going to hold all of these variables and let's just call it quest it's probably also a good idea that our quest giver has access to our player so that when he wants to give the quest to our player we can reference him and actually set the quest so let's also create a public player and let's just call it player and if we just save this right now without writing any extra logic we should be able to go into unity and our quest giver now has the field for a player so we can simply take our player object and drag it in there however we are not able to currently see our quest here and that's weird because we should have a title and description and some rewards but they're not currently showing up the reason for this is that if we want this stuff to show up in unity we first need to mark the quest class as system that's serializable this way unity knows that it can serialize these fields and so they will show up in the inspector and indeed it does now under a quest here we can define all these values so I'm gonna give it a title I'm gonna call it on the hunt for the description I'm gonna write venture out into the wild and kill three enemies to get the reward as the experience reward I'll set 30 and for the gold I'm gonna set 780 and by default I don't want this to be active it's now that we have a reference to a player and we've created a quest we're ready to define what's gonna happen when every this quest is given so in my case I'd like to do in two steps the first one is whenever we press quest I want a quest window to pop up then the player has the option to accept this quest and if he does the quest is going to be given to the player if not nothing's gonna happen so to do this I'm gonna disable the quest window and I'm gonna go into our quest giver script and I'm gonna make a function called public void open quest window and to open this window we first need a reference to it so I'm gonna create a public game object I'm gonna call it quest window and now inside of our function we can basically say quest window dot set active to true we also want to make sure that we update all the info on our quest windows so inside of our quest window we of course have the title text the description the experience in gold so let's go ahead and create references for this will create a public text and in order to access the text type we need to be using unity engine WI and will call this title text also create another public text we'll call this one description text create another one you guessed it experience text and gold text then when we open the quest window we'll go ahead and set title text dot text equal to quest title we'll do the same for description text dot text set it equal to quest dot description experience text the text equals quests that experience reward and since this is an integer we need to do dot to string to convert it into a string I will do the same thing with gold text awesome so if we save this go into unity and select our quest giver we now have fields for all this stuff so for quest window we'll drag in the window itself for our title text we'll drag in the UI title here we'll drag in the description XP and gold and if we now disable this quest window and go into our player window and select the quest button we can add an on-click event so I'm gonna add a new one I'm gonna put in our quest giver here and I'm gonna make it so that whenever we press this button we're going to go to a quest giver and called the open quest window function and this is again one of those examples where you might not want to do this using a button on the UI you might want to do this when you speak to an NPC or when you reach a certain level that's completely up to you but just for simplicity's sake I'm calling this through the UI so if we now play and hit the quest button we can see that a window pops up it says on the hunt venture out into the wild and kill three enemies to get the reward we have 30 XP as a reward and 780 gold if we press accept nothing happens that's the next thing that we should do we should go ahead and create a public void here let's call this one accept quest and when we do this we want to go quest window dot set active to false so disabling the quest window again we also want to set the quest to active because we've now accepted it so quest that is active equals true and finally we want to give this quest to our player so how do we most efficiently do this well one way would be to simply go to our player script and create a variable here of type quest called quest this way inside of our quest giver script we can simply go player that quest equals the quest really really simple of course this will only allow you to have one quest at a time if you want to have multiple quests you can simply turn this into a list where you can just add quests and run time but for now let's keep it at one so now in the UI we need to go to the quest window and find the accept button and whenever we click on this we want to go to the quest giver and access the function called accept quest if we play this we should see that if we press a quest hit accept and then select a player he now has a quest that is active with all the information that we've given awesome so the final thing that's left to do is to track our progress in this quest in other words we need to define some kind of quest goal that we can try to reach because right now we can find as many times as we want we're never going to reach the end of this quest so to do that let's go ahead and create a separate script let's create a sub script and let's call it quest goal I'm gonna double click on this we want to remove the two functions and also this shouldn't derive from mono behavior now you're probably going to have different goals for different types of quests some quests are gathering quests where you need to go and find as many objects as possible others are kill quests where you need to kill a bunch of enemies sometimes of a certain type and depending on the type of goal there are different actions that we need to take to further our progress in the quest now they're definitely multiple ways to set this up we're gonna take a fairly similar route here using enums to define the cold type but you could definitely also do this using inheritance in fact if that's the way you want to go I'm gonna have a link in the description to a series that shows you how to do that so first we need to define the different types of goals to do this we'll go under the class and create a public enum and we'll call it gold type and here we can define the different types we're gonna have a kill quest a gathering quest you could easily input more here such as an escort quest or maybe actually not that one I've played too much water for craft to include that one so once you've defined the different types we can go to the top here and we can create a public gold type and let's call it gold type we also need a way to keep track of our progress in the quest so we'll go public int required amount and public int current amount so if we need to kill three enemies we'll set required amount to three and whenever your current amount is three or more the quest is complete let's actually create a quick function for checking this so let's create a public fold because we're going to return true or false and let's call it is reached to check if the goal has been reached here we'll simply return and the boolean that we want to return is current amount is greater than or equal to required amount and if you've never seen this syntax before we're basically just saying that if this here is true so if our current amount is equal to or exceeds the requirement then we'll return true for this function if not then we'll return false so it's pretty cool shorthand syntax we also need to go to the top here and mark this class as system dot serializable because we want to be able to edit it inside the inspector and if we now go into our quest at the bottom here we'll go ahead and add a public quest goal and we'll just call it goal and save this we can go into unity and select our quest giver and we now see that under our quest we also have this goal we can select a goal type between kill and gathering I'm just going to leave this one and kill and a required amount let's set that to three for this quest really really cool but how do we increase the current amount well to do this we could go into the player script and whenever your player goes into battle we lose some health and gain some experience and some gold but we also kill an enemy so this is probably a good place to access our quest and let it know that we've killed an enemy - that will write if quest dot is active we only want to do this if we've accepted the quest in that case we can go quest dot goal and here we want to trigger some kind of function inside of our goal that lets it know that we've killed an enemy so let's go into our quest goal and let's create a public void enemy killed and here we can simply take the current amount and increase it by one but of course we don't want to do this if this is a gathering quest so if the go type is set to gathering then we don't want to further our quest by killing an enemy so let's just create a quick if statement here saying that we only want to do this if the goal type is equal to goal type dot kill and if that's the case but then we'll increase the current amount if you want the quest to only be about certain types of enemies this would also be a good place to do it you could for example give all the enemies for this quest a certain tag and then pass in the tag of the enemy killed as an argument and then in here you could check if the tag of the enemy killed corresponds to the tag for this quest so you can see how this is fairly modular you could also go ahead and do pretty much the same thing for items so if this was a gathering quest well then instead of an enemy killed we could do and item collect it and in this case we only want to increase the current amount if the gold type is equal to gold type gathering so it's really easy to expand upon this with other types of quests again this is not a solid as using inheritance but it will get you pretty far so now we can go into our player and now we have a function here so quest goal dot and killed constantly called that function and we can even check if we completed the quest by doing so so if quest dot goal that is reached well then we just complete the quest and we can go ahead and increase our experience so we'll say experience plus equals quest experience reward gold plus equals quest stud gold reward and we also probably want to mark our quest as complete so let's go quest start complete and this is not a function that we've created yet so let's save that go into our quests let's create some kind of complete function here so public void complete and for this example we'll set is active to false so that we don't have the quest anymore let's also just throw out a debug deadlock saying that the title of the quest was completed and that should be the end of a questing system if we now go into unity hit play take a look and our player here we can currently see that we don't have an active quest all this is empty and the quest is not active if we then hit the quest button a window appears if we accept it we get the quest on the player we can then fight a few enemies you can see each time we do the current amount in our goal goes up and once it reaches three we get a bunch of experience a bunch of gold and it says down here that the quest on the hunt was completed yay from here it's really up to you to implement this system into your own game come up with a bunch of fun quest types and really just go nuts with it this is not a perfect fully fledged system but it should act as a good baseline to build upon again if you want to go more in depth with your questing system I will have a link in the description to where you can learn more about how you can use inheritance and delegates to make it even more solid but I'm just gonna stick with this for now that's pretty much it for this video if you haven't already joined the practice game jam I definitely recommend you do so now and don't forget to check out Skillshare simply click the link in the description to get started on that thanks for watching and I will see you in the next video thanks to have the awesome patreon supporters who donated in January and special thanks to James P Jax - Bert and you can link Oh John Shannon infinity PPI Sybok mommy Dennis Sullivan Travis Dylan faceverify Lila set Ronan Clinton Vince Kyra Chris Gregory Pierce killed Swedish key Rathbun Timah photo park and Rasmus you guys Rock
Info
Channel: Brackeys
Views: 168,031
Rating: undefined out of 5
Keywords: brackeys, unity, unity3d, asset, assets, model, beginner, easy, how, to, howto, learn, course, series, tutorial, tutorials, fix, tip, game, development, develop, games, programming, coding, basic, basics, C#, quest, UI, enums, quests, intermediate, questing, system, task, goal, challenge, goals, rpg, fantasy
Id: e7VEe_qW4oE
Channel Id: undefined
Length: 18min 9sec (1089 seconds)
Published: Sun Feb 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.