Game Development Reference
In-Depth Information
Updating the BattleManager state with a weapon
Finally, we return to the BattleManager state and decide what to do with this new
weapon the user has selected. First we need a variable to store the selected weapon in, so
add the following to the top of the BattleManager script with the rest of the variables:
private InventoryItem selectedWeapon;
Next we need a handler function to store the new selected weapon:
private void InventoryItemSelect(InventoryItem item)
{
selectedWeapon = item;
}
Then, we have to wire up this function to the event we are broadcasting from the
BattleManage r state in the Start method:
MessagingManager.Instance.SubscribeInventoryEvent(InventoryItemSelect);
Now we know what the player is fighting with, let's update the UI with some instructions.
So far, when the battle starts in the state machine, an intro is shown and then two seconds
later, it is the player's turn; however, at the moment, the player is completely unaware of
this, so let's update the OnGUI method in the BattleManager script as follows:
void OnGUI()
{
switch (currentBattleState)
{
case BattleState.Begin_Battle:
break;
case BattleState.Intro:
GUI.Box(new Rect((Screen.width / 2) - 150, 50, 300,
50), "Battle between Player and Goblins");
break;
case BattleState.Player_Move:
if (GUI.Button(new Rect(10, 10, 100, 50), "Run Away"))
{
GameState.playerReturningHome = true;
Search WWH ::




Custom Search