[HOWTO] How To: Create Custom Actions
Posted: Tue Oct 06, 2020 1:37 pm
Quest Machine lets you define your own quest actions that appear in action dropdown menus just like the built-in actions (Audio, Alert, SetQuestState, etc.).
It's easy to add your own actions. In this example, we'll add an action called "Win Game". It assumes you have a manager script named GameManager defined roughly like this:
To add a "Win Game" action:
It's easy to add your own actions. In this example, we'll add an action called "Win Game". It assumes you have a manager script named GameManager defined roughly like this:
Code: Select all
public class GameManager : MonoBehaviour
{
public static GameManager Instance {get; set;}
public void WinGame()
{
// Your code here to set the game to the winning state.
}
...
- Duplicate the file QuestActionTemplate.cs located in the Templates folder. Move it into your own scripts folder and rename it to WinGameQuestAction.cs.
- Open the script and rename the class to the same name (WinGameQuestAction).
- Configure the Execute method to call the GameManager's WinGame() method. Example:
Code: Select all
public class WinGameQuestAction : QuestAction { public override void Execute() { base.Execute(); GameManager.Instance.WinGame(); } }
- Now you can select your new Win Game action from the dropdown menu in your quests' Actions sections.