Game Development Reference
In-Depth Information
MessagingManager.Instance.BroadcastInventoryEvent(null);
}
}
To finish off the
CommandBar
script while we are updating its messaging, let's also sub-
scribe to the UI event's message and link it to the
canSelectbutton
variable/property
we added earlier.
So, create a new delegate method called
SetCanSelectButton
:
void SetCanSelectButton(bool state)
{
canSelectButton = !state;
}
Then, update the
Start
function in the
CommandBar
script as follows:
void Start () {
InitCommandButtons();
MessagingManager.Instance.SubscribeUIEvent(SetCanSelectButton);
}
Don't forget to unsubscribe the event from it as well when the command bar is destroyed
by adding the
OnDestroy
method:
void OnDestroy()
{
if (MessagingManager.Instance != null)
{
MessagingManager.Instance.UnSubscribeUIEvent(SetCanSelectButton);
}
}
Now whenever the UI is locked, we ensure that no further button presses are allowed,
such as for events when the player has attacked the enemy.