0
\$\begingroup\$

enter image description here

I want to perform some specific functionalities if my character is in Idle state and IdleUnarmed animation is playing and !anyKeyDown. I do not know how to access that "IdleUnarmed" animation from animator. The code i am using is

int idle = Animator.StringToHash("Base Layer.Locomotion.Free Locomotion.Free Locomotion.Idle.IdleUnarmed");
        AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);
        if (!Input.anyKeyDown && stateInfo.GetHashCode() == idle)
         {
            if (Time.time > currentTime)
            {

But it is not working. Anyone please help me to sort out this issue. Thank you

\$\endgroup\$
3
\$\begingroup\$

Check out the Animator.Play() function: https://docs.unity3d.com/ScriptReference/Animator.Play.html

\$\endgroup\$
  • \$\begingroup\$ I have seen it but did not get it. Can you please tell me how can i use this function to achieve my purpose? Thank you \$\endgroup\$ – Ali Zaki Nov 15 '17 at 6:26
  • \$\begingroup\$ Here is how it works: public void Play(string stateName, int layer = -1, float normalizedTime = float.NegativeInfinity); the statename parameter specifies the name of the animation to play(the name that you assigned to the state in the animator), the layer is the layer where the state is, normalized time is the normalized time of the animation(A value of 1 is the end of the animation. A value of 0.5 is the middle of the animation). Now, are you sure that Animator.StringToHash returns the correct ID of the animations? \$\endgroup\$ – user100681 Nov 15 '17 at 6:46
  • \$\begingroup\$ No. This is the main problem i am getting. I do not know if ID is correct or not. i want to enter in this if condition ''if (!Input.anyKeyDown && stateInfo.GetHashCode() == idle)'' \$\endgroup\$ – Ali Zaki Nov 15 '17 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.