When your item is being used you may not always want the same animation to play. As an example you may want your sword to first slash from the right and then slash from the left. This can be setup using the Animator Audio State Set. Consider the following example:
In this example the item has two different Animator Audio States. The selected state has an Item Substate Index of 1 and three audio clips. When this state is triggered it will change the Animator’s Item Substate Index value to 1 and randomly choose one of the audio clips. When the next state is called it’ll move onto the second state in the list. This can be changed by adjusting the Selector popup that is above the Animator Audio States reorderable list.
The selector popup is a powerful feature which allows the state to be selected based on the current game state. The following selector classes are included:
- Constant Recoil: Selects a state based on the recoil type. Allows the returned state to be returned if the hit object blocks the attack or not.
- Random: Selects the next state randomly.
- Sequence: Will select the next state sequentially.
You can also create your own selection objects by extending the Animator Audio State Selector object. The GetStateIndex method will return the index of the state that should be triggered. The NextState method indicates that the next state should be prepared. This can be used to determine which state should be returned within GetStateIndex.