I am attempting to determine tips on how to play a sound impact when a recreation object leaves a selected state and goes into one other. For simplicity, let’s simply say I need a sound impact to play when the animation for an object transitions from state A to state B, however not the opposite method round and never for different states. How would I obtain this? I’ve discovered info associated to enjoying sound results when coming into a state, however not when exiting from one explicit state to a different.
To be extra particular, I attempted implementing this code as a habits on State A exit:
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
GameObject self = animator.gameObject;
MyScript myScript = self.GetComponent<MyScript>();
myScript.PlaySFX();
}
However since state A is accessible from any state, I feel it’s continuously coming into state A from itself again and again. I say this as a result of the sound impact performs repeatedly at any time when I’m in state A.