What I’m trying to do is just that my models (2 or more) start walking when I click on them!
I have a model with 2 animations, let’s say “Walk” and “Idle”. Walk animation starts when my bool parameter “isWalking” is setted to true (currently handled by the behaviour when the model is clicked). This work fine as expected.
The problem comes when I have two or more instances of the model and its behaviour. When I set the paremeter “isWalking” true, both instances start the walking animation.
Is this the normal behaviour of mecanim? If it is, what are the best practices in order to control the animation states of two or more different model instances?
Animator animator;
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (animator.GetCurrentAnimatorStateInfo(0).IsName("Base.Walk"))
{
animator.SetBool("isWalking", false);
}
RaycastHit hit;
if (Input.GetMouseButtonDown(0))
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
animator.SetBool("isWalking", true);
}
}
}