How to Set Up a Quest Script in Unity
Zenva
ACCESS the FULL COURSE here: https://academy.zenva.com/product/rpg-academy/?zva_src=youtube-rpg-academy
TRANSCRIPT
Hey guys, welcome back. In this lesson, we're going to set up our quest script file. So I wanna create a new C-sharp script inside of my questing folder here, and I wanna call it quest. Now, this is gonna be the base class that all of our quests are actually deriving from. So first of all, let's think about what is a quest? What does a quest need? It's gonna need a name, it's gonna need maybe a description, if you wanna show that in your UI. It's gonna need a goal, based on the goal class that we just wrote there. It's gonna need to know whether it's been completed or not, maybe a list of potential items rewards, or potential experience rewards. Whatever your game would need for that. So, let's start with what we know, we're gonna have a public string quest name. Have a public stream called description, maybe, I'm sure ill use this in the UI, but this will be there if you want it. A public goal, now the goal that we just created, so then we're gonna say, no, we'll just call it goal. And then, a Boolean that's true or false if we have completed it, so completed. And then, we can also set up that list of, maybe, just some items we can do for now. Later on, in the integration course, we will set up the inventory system with the questing system, so that you can actually have a item rewards work with the inventory and crafting system that we set up in the past. It's gonna a list, for now it's gonna be string, later on it'll be item ID, so our item names. And it's gonna be items rewards, that's all the data that a quest is gonna need for now.
I also wanna have a public method that we can call to complete the quest. So, if we we're to actually complete the goal, then it can say, okay complete the quest and grant the reward to the player, whatever that might be. So, I'll say complete. Whenever we call complete, then we will, maybe for not just log out. (typing) Quest completed. (typing) I also wanna have a method that's going to grant the reward, so if we have, again, a list of items, I wanna go through each of those and add it to the inventory, but for now, we'll just say, hey look what you got in the console. So, it'll be a public void grant reward, (typing) and I'll again just log out here. (typing) Turning in quest, granting reward. And then for now, I'll just say, for each of these strings in item rewards, I'll just log out what we got as a reward. So, I'll say string item in item rewards. So, for each string in item rewards, that we called item, we will do a simple log, and just log it out. Maybe concatonate onto the front of that, rewarded with. (typing) Just like that, pretty cool. And now once all this is said and done, and once we ... https://www.youtube.com/watch?v=ieBZssJH1UI
20887333 Bytes