[HOWTO] How To: Create Custom Actions

Announcements, support questions, and discussion for Quest Machine.
Post Reply
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Create Custom Actions

Post by Tony Li »

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:

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.
    }
    ...
To add a "Win Game" action:
  • 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.
Post Reply