Creating your own MenuOptions

Introduction

There are a lot of built in Menu Options, but if it isn't enough you can create your own. By inheriting the Menu Option class you can make your custom Interactables change settings in game.

Creating your own MenuOptions

To create a Menu Option you have to inherit the MenuOption class. It is a base for assigning labels and tags to your interactable. You will also need to override LoadOption - where you assign the correct value to your interactable and GetLabel - where you return the label that will be displayed.

public class OptionsExample : MenuOption
{
    private Button button;

    private void Awake()
    {
        button = GetComponent<Button>();
        if (_button != null) button.onClick.AddListener(OnButtonClick);
    }
    
    void OnButtonClick()
    {
        //Handle OnClick
    }

    public override string GetLabel()
    {
        //This is where you return the label
        string value = "Insert value here";
        return $"{optionLabelName}{value}";
    }

    public override void LoadOption()
    {
        //Assign the correct value to your interactable
    }
}

Methods

Method

Description

LoadOption

Assigns a value to the interactable.

SetValue

Changes the value of the targeted option.

GetLabel

Returns the label that will be displayed in the menu.

Properties

Property

Description

nameText

A TMPro Text that will display the label.

optionLabelName

Text that will be displayed before the value in the label.

optionName

Name of the option

save

If the setting should be saved when changing.

Last updated