Game Development Reference
In-Depth Information
Next, we need to update the MapMovement script to add in the messaging handlers so
that the script knows when the GUI is displayed. So, add the following Start function to
subscribe to the MapMovement script for the new UI events:
void Start()
{
MessagingManager.Instance.SubscribeUIEvent(UpdateInputAction);
}
Then, add the corresponding function to toggle the inputActive flag we created earli-
er:
private void UpdateInputAction(bool uiVisible)
{
inputActive = !uiVisible;
}
This just updates the inputActive property whenever the GUI informs us that it's on-
screen.
Note
If you haven't done it yet, update the MessagingManager script based on the example
in the Managing input section to add the new UI event handler. Additionally, update the
NavigationPrompt script to inform the message handler when the GUI is visible.
Tip
If you like Lamdas, you could actually write the preceding code to subscribe to the Mes-
sagingManager line as follows:
MessagingManager.Instance.SubscribeUIEvent(uiVisible =>
inputActive = !uiVisible);
However, I've kept it simple in the project for all to read and it's a good practice to keep
them separate in case you need to add more handling.
For more information on Lamdas, see the MSDN article at http://msdn.microsoft.com/en-
gb/library/bb397687.aspx .
Search WWH ::




Custom Search