Faster GetCurrentAnimatorStateInfo(0).IsTag

Hey All! I’m currently revising and touching up my game and I’ve run into the problem where I’m transform.translating during other animations, which I obviously do not want. This is what I currently have. It prevents transform.Translate being called when I’m playing a different animation & pressing W (which is not necessary, but may be accidental or habitual).

if (Input.GetKey (KeyCode.W)) {
             anim.SetBool("isRunning", true);
             anim.SetBool("isIdle", false);
             anim.SetBool("isWalking", false);
   
             if (anim.GetCurrentAnimatorStateInfo(0).IsTag("Run")){
                 transform.Translate(Vector3.forward * speed * Time.deltaTime);
             }


         }

This works, but has about a .5 second delay and quite noticeable when playing. Is there a way to speed up getting the current state info? Or perhaps someone has a better idea to only transform.Translate during the Running animation.

After trying different things it just would not work this way, so I did it differently.

I attached a behaviour to the actual animation in mecanim and transform.Translate from there. It’s faster, thus exactly what I wanted. :slight_smile: