This is why I requested a tutorial. The information you just posted is not a complete set of instructions on how to use UIEventListener. Adding that line of code you provided to a script does not actually do anything for me.
I readily accept that I'm slow and may need additional help that others do not require
So perhaps you can help me figure out this problem - I want to set up a script named TestManager to handle what happens when a button on a menu is clicked. Here's the UI I've created so far (the button I'm trying to set up is highlighted):
Next I added UIButtonMessage to this button. I've set the target to "_TestManager" (game object in the scene with the TestManager.cs script attached) and I've set the function name to "OnButtonCloseClicked."
Then I attempted to set up TestManager.cs like this:
public class TestManager : MonoBehaviour
{
public UIPanel pMenu;
public GameObject buttonClose;
public bool displayMenu = false;
// Use this for initialization
void Start ()
{
UIEventListener.Get(buttonClose).onClick += OnButtonCloseClicked;
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
displayMenu = !displayMenu;
NGUITools.SetActive(pMenu.gameObject, displayMenu);
}
}
void OnButtonCloseClicked()
{
displayMenu = false;
NGUITools.SetActive(pMenu.gameObject, displayMenu);
}
}
This does not work and generates errors. Please help me to understand what the problem is.
I imagine I have not properly set up the UIEventListener stuff, because this is the first error I'm getting:
Assets/Scripts/test/TestManager.cs(21,50): error CS0123: A method or delegate `TestManager.OnButtonCloseClicked()' parameters do not match delegate `UIEventListener.VoidDelegate(UnityEngine.GameObject)' parameters
Additional question: Is GameObject the correct type to use for the buttonClose variable? I see other NGUI elements like UILabel and UIPanel (which I'm using), but there isn't one for UIButton...