Animator not switching states properly

My animator has a transition going from idle to walk called “State” and it goes from integer 1 and 2, but the darn thing won’t shift to my walk animation unless I jump first and its a bummer to fight with this for so long.

Here is my :Player code containing the animator code: link text

2 comments and an answer:

  1. It’s usually more useful if you copy code into your question (using the “101010”-Button above the input field) than post your code as a screenshot.
  2. It would usually be useful to see your animator configuration as well (here, a screenshot makes sense)

To your question, it is pretty obvious why you need to jump first, because you code is:

if(Input.GetKeyUp(KeyCodeSpace)) {
    // ...
    if(Input.GetAxisRaw("Horizontal") != 0) {
        anim.SetInteger("State", 2);

So the Line

anim.SetInteger("State", 2);

can only be reached in the very frame the Space-Key is released (see Unity - Scripting API: Input.GetKeyUp) and since Space is appearantly your Jump-Key, it makes sense that you observe the Transition only happens after jumping.

Did you check your transitions in animator? If don’t check if you have a transition from idle to walk that have integer condition.

For example in this animator transitions while Joey_walking_up animation is active animation cant goes bak to idle animation directly but if it is idle it can walk up. Because transition is from idle to walking up not from walking up to the idle. I wish this answers you question.

@jwulf Thank you I was in such a rush to complete the code before my other plans came that I completely overlooked where the code was sitting. Thanks so much