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);
}
}
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:
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:
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!
Comments
myMenu.TurnOn ();
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.
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:
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:
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:
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!