Hi,
I'm trying to build a menu that has a row of buttons and one big label on it. When I press one of the buttons I want the text in the label to change. So basically all I want is the click on a button to trigger a custom function that fills up the label with the right string. But nothing seems to happen.
I wrote this function:
public void ShowNotes (int item) {
if (item == 0) {
PlayerMenus.GetElementWithName("Dossier", "Notes").title = "Bla bla bla bla";
}
}
When I click a button on the menu it sends a message to this function with an int (can't send strings to custom functions?) through a menuactionlist. But I get a null reference (int32) when I try to trigger this, and nothing happens. The script I'm trying to talk to is attached to a gameobject in the scene with a custom ID script to reference it.
I've tried stuff like this before to update the text on a button but I can't seem to get scripts to influence AC elements in any way. And there is no scripting reference to turn to so here I am.
I've also tried:
- putting a journal instead of a label, but I can't jump to a specific journal page
- making each label text its own menu and toggling those when pressing the buttons - yikes
- using items instead of buttons and having their use action trigger a journal update
Am I better off building a menu through script with UnityGUI?
Comments
MenuLabel labelElement = (MenuLabel) PlayerMenus.GetElementWithName ("Dossier", "Notes");
labelElement.label = "Bla";
However, you do have a couple of other options:
1) You display multiple Labels in the same place, but only one shown at a time. The idea being that you switch display from one to another when you click the Button. You can use the Menu: Change state Action to show and hide Elements in a Menu.
2) Set the Button's Click type to Custom Script. Then in MenuSystem.cs, you can type the code that you want to be executed in the OnElementClick function:
if (_menu.title == "Dossier" && _element.title == "Notes")
{
MenuLabel labelElement = (MenuLabel) _menu.GetElementWithName (_element.title);
labelElement.label = "Bla";
}