Forum rules - please read before posting.

How to show a menu from code?

edited May 2017 in Technical Q&A

I want to specify a menu to turn on a menu with code, is there any reference on how to do that ? Edit: solved i ran a cut scene from code instead. 

Comments

  • edited May 2017
    AC.Menu myMenu = AC.PlayerMenus.GetMenuWithName ("MyMenuTitle");
    myMenu.TurnOn ();
  • Nice!..  I like the easy access to everything.
  • Hey Chris, I'm new here and I'd like to say thanks for the Adventure Creator! It's a really amazing tool!

    I have a problem in my code: the "TurnOn" method is not activating the Menu during the game. The code is below, as well as images. The idea is to make the Menu activate whenever an objective has its state changed.

    public class QuestHUDInGame : MonoBehaviour
    {
        private void Awake() { EventManager.OnObjectiveUpdate += OnObjectiveUpdate; }
    
        //AC: An event triggered when a Objective's state is changed
        private void OnObjectiveUpdate(Objective objective, ObjectiveState state)
        {
            //Get the Menu elements
            AC.Menu objectiveMenu = KickStarter.menuManager.GetMenuWithName("ObjectiveInGame");
            AC.MenuLabel titleMenu = objectiveMenu.GetElementWithName("QuestTitle") as MenuLabel;
            AC.MenuLabel stateMenu = objectiveMenu.GetElementWithName("QuestState") as MenuLabel;
    
            //Change the HUD information
            titleMenu.label  = objective.GetTitle();
            stateMenu.label = state.GetLabel();
    
            //Refreshing the Menu
            objectiveMenu.TurnOn();
            KickStarter.playerMenus.RebuildMenus (KickStarter.menuManager);
        }
    
    }
    
  • edited February 2022

    Welcome to the community, @davimedio01.

    There are two GetMenuWithName functions in AC - one inside MenuManager, and another inside PlayerMenus. You'll want to call the latter, not the former, to affect Menus at runtime:

    AC.Menu objectiveMenu = PlayerMenus.GetMenuWithName("ObjectiveInGame");
    

    Bear in mind that your Menu must have an Appear type set to Manual for it to be turned on via script. Otherwise, you'll need to unlock the menu instead:

    objectiveMenu.IsLocked = false;
    

    You'll also want to unregister your event hook inside an OnDisable function, so that the event isn't registering multiple times upon re-enabling the script. Use this instead of your current Awake function:

    private void OnEnable() { EventManager.OnObjectiveUpdate += OnObjectiveUpdate; }
    private void OnDisable() { EventManager.OnObjectiveUpdate -= OnObjectiveUpdate; }
    
  • Thank you so much! I read the rules right now, so sorry about the beggining lmao.
    You tool is really really nice! The code above works much fine, really thank you again!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.