- Home /
Character states using Unity animation system and StateMachineBehaviour
I'm trying to use Animator to control my character states. I've build a simple example where cube changes color depending on state
Behaviour code looks like this:
using UnityEngine; public class CubeIdleBehaviour : StateMachineBehaviour { override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { animator.gameObject.getComponent<Renderer>().material.color = Color.red; } }
"animator.gameObject.getComponent" is ugly enough, but all i want is to pass variables to this behaviour. I have component with private color variable and i don't wont to make it public. So my questions are:
Is it possible with this implementation to pass private variables to StateMachineBehaviour?
Do i really need to use some other supercomplex FSM just to do this simple stuff?
Am i bound to use switch/case?
Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220612213758im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Non-resource texture scope 1 Answer
"ref float" is not compatible with the argument list "float" 1 Answer
Component not being accessed in ArrayList 1 Answer
Multiple States or Fewer States 0 Answers