Game Development Reference
In-Depth Information
foreach (BattleState state i
(BattleState[])System.Enum.GetValues(typeof(BattleState)))
{
battleStateHash.Add(Animator.StringToHash("Base Layer."
+ state.ToString()), state);
}
}
This simply generates a hash for the corresponding animation state in Mecanim and stores
the resultant hashes in a dictionary that we can use without having to calculate them at
runtime when we need to talk to the state machine.
Note
Sadly, there is no way at runtime to gather the information from Mecanim as all the
classes for interrogating the animator are only available in the editor.
You could gather the hashes from the animator and store them in a file to avoid this, but it
won't save you much.
To complete this, we just need to call the new method in the Start function of the
BattleManager script by adding the following:
GetAnimationStates();
Now that we have our states, we can use them in our running game to control both the lo-
gic that is applied and the GUI elements that are drawn to the screen.
Now add the Update function to the BattleManager class, as follows:
void Update()
{
currentBattleState =
battleStateHash[battleStateManager.GetCurrentAnimatorStateInfo(0).nameHash];
switch (currentBattleState)
{
case BattleState.Intro:
break;
case BattleState.Player_Move:
Search WWH ::




Custom Search