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:
- Matching Recoil: Selects the same state index as what was retrieved by the Use Animator Animator State Selector
- Random: Selects the next state randomly.
- Random Recoil: Selects the next state randomly for a recoil.
- Sequence: Will select the next state sequentially.
- Sequence Recoil: Selects the next state sequentially for a recoil.
When the selector is determining what state can be selected it will first ensure that the possible state can be selected. Cases when it may not be able to be selected are if Allow During Movement is false but the character is moving or Require Grounded is true but the character is not grounded. When the state is selected the state with the specified State Name will activate allowing for states to change the character’s state. An example use may be that when the state at index 2 plays the melee weapon should cause more damage because it is a heavy attack.
You can also create your own selection objects by extending the Animator Audio State Selector object. The Animator Audio State Selector has the following API:
/// <summary> /// Initializes the selector. /// </summary> /// <param name="gameObject">The GameObject that the state belongs to.</param> /// <param name="characterLocomotion">The character that the state bleongs to.</param> /// <param name="item">The item that the state belongs to.</param> /// <param name="states">The states which are being selected.</param> public virtual void Initialize(GameObject gameObject, UltimateCharacterLocomotion characterLocomotion, Item item, AnimatorAudioStateSet.AnimatorAudioState states); /// <summary> /// Starts or stops the state selection. Will activate or deactivate the state with the name specified within the AnimatorAudioState. /// </summary> /// <param name="start">Is the object starting?</param> public virtual void StartStopStateSelection(bool start) /// <summary> /// Returns the current state index. -1 indicates this index is not set by the class. /// </summary> /// <returns>The current state index.</returns> public virtual int GetStateIndex() /// <summary> /// Moves to the next state. /// </summary> public virtual void NextState() /// <summary> /// Returns an additional value that should be added to the Item Substate Index. /// </summary> /// <returns>An additional value that should be added to the Item Substate Index.</returns> public virtual int GetAdditionalItemSubstateIndex()