Hello.
I’m following the example provided in the Unity documentation about how to get and set parameters of the animator.
The script is inside of a State inside of a layer of the animator, and it is not compiling as it says.
UnassignedReferenceException: The variable animator of SnorHelmetRemove has not been assigned.
You probably need to assign the animator variable of the SnorHelmetRemove script in the inspector.
UnityEngine.Animator.GetBool (System.String name) (at <95298f2688224d229ba67639574988c7>:0)
SnorHelmetRemove.OnEnable ()
I am following the documentation. Why I am not getting the Animator?
This is the code.
public class SnorHelmetRemove : StateMachineBehaviour {
private Animator animator;
private int headSwitch;
private int previousHeadSwitch;
private void OnEnable() {
animator = GetComponent<Animator>();
}
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
previousHeadSwitch = animator.GetInteger("HeadSwitch");
animator.SetInteger("HeadSwitch", 0);
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if(previousHeadSwitch == 1)
{
animator.setInteger("HeadSwitch", 2);
}
else
{
animator.SetInteger("HeadSwitch", 1);
}
}
}