Game Development Reference
In-Depth Information
}
}
We are done with the
EnemyController
script now.
To finish off the selection logic, let's return to the
BattleManager
script and add the
two missing functions as follows:
public void SelectEnemy(EnemyController enemy, string name)
{
selectedTarget = enemy;
selectedTargetName = name;
}
public void ClearSelectedEnemy()
{
if (selectedTarget != null)
{
var enemyController =
selectedTarget.GetComponent<EnemyController>();
enemyController.ClearSelection();
selectedTarget = null;
selectedTargetName = string.Empty;
}
}
Both the functions are very simple. They either set the two variables we created earlier for
the
selectedTarget
and the
selectedTargetName
variables, or clear these val-
ues, get the
EnemyController
component for the selected target, and use the
ClearSelection
function we just added.
However, we still can't select the enemy to attack yet, as our
BattleManager
script
does not let us do it. Since we want to control the flow of what the player does, we do not
enable this until they have first selected a weapon; if there is no selected weapon, there is
no enemy selection.
To enable you to select an enemy and then progress on to the battle, we need to update our
OnGUI
method again for the additional actions. So, alter the
case
BattleState.Player_Move
section of the
OnGUI
method as follows: