Generate a Unity script which allows you to access your Animator values without having to use string variables.
- Import the ScriptableAnimator.cs into your Unity Project
- Open up your Animator in the Inspector and hit the "Generate Script" Button. This creates a two new Scripts in the Folder "Assets/Generated/Animator" A State.cs, which is just a helper class, and a class with the name of your AnimatorController like "PlayerAnimator.cs"
- Add this PlayerAnimator Script to the same Object the Anomator is attached to 4 Done!
Store a Reference in the Script you wan't to use the Animator
using IG.Generated.gAnimator;
...
private PlayerAnimator animator;
private void Awake()
{
animator = GetComponent<PlayerAnimator>();
}
// set a Trigger
animator.Parameter.SetJump();
// set a value
animator.Parameter.Running = true;
The scripted Animator stores the animations in the same layered way the animator does, so if you want to call a animation on your "Base" Layer
you would call animator.base.attack.Play();
If you use substates you could start the substate with the entrystate exactly the same by calling animator.base.substate.Play();
or play a childstate by calling animator.base.substate.child.Play();