title: Unity - Animations - Animation Doesn't Flip Left/Right
body: <p>I have code that works for flipping the player to face the direction that it is moving upon the X-axis. However, since I have added animations, the animation will play, but will not flip in the other direction.</p>
  
  <p>Notes-</p>
  
  <ol>
  <li>I'm not accessing an Animator to run my animations</li>
  <li>I created AnimationClip variables</li>
  <li>I play my animations GetComponent().Play("Idle");</li>
  <li>I do have an Animation component added to my player controller with
  fields for each animation inserted.</li>
  </ol>
  
  <p>Code</p>
  
  <pre><code> [SerializeField]
   private AnimationClip idle;
   [SerializeField]
   private AnimationClip walk;
   [SerializeField]
   private AnimationClip hop; // Alternative name for JUMP
   [SerializeField]
   private AnimationClip death;
  </code></pre>
  
  <ol start="5">
  <li>The code I have below works perfectly, However, making a transition to Jump has proven difficult.</li>
  </ol>
  
  <p>Code</p>
  
  <pre><code>  if (Mathf.Abs(player.velocity.x) &gt; 0)
      {
  
          GetComponent&lt;Animation&gt;().Play("Walk");
      }
      else
      {
  
          GetComponent&lt;Animation&gt;().Play("Idle");
  
      }
  </code></pre>
  
  <ol start="6">
  <li>The code below for jump DOESN'T play the animation:</li>
  </ol>
  
  <p>Code</p>
  
  <pre><code>    if (Input.GetKeyDown(KeyCode.Space) &amp;&amp; onFloor==true || 
      Input.GetKeyDown(KeyCode.W) &amp;&amp; onFloor==true)
      {
  
          player.velocity = new Vector2(0, jump);
          onFloor = false;
         // GetComponent&lt;Animation&gt;().Stop("Walk");
         // GetComponent&lt;Animation&gt;().Stop("Idle");
          GetComponent&lt;Animation&gt;().Play("Jump");
  
      }
  </code></pre>
  
  <ol start="7">
  <li>I tried to stop all other animations and only play the jump
  animation.</li>
  <li>None of that worked. Why? And what would be a solution?</li>
  <li>My animation clips will play but won't flip to the left.</li>
  </ol>
  
  <p>Code</p>
  
  <pre><code>        faceRight = !faceRight;
          Vector3 Pscale = transform.localScale;
          Pscale.x *= -1;
          transform.localScale = Pscale;
  </code></pre>
  
  <ol start="10">
  <li>I have tried inserting the animation for walking inside the Pflip()
  which is what you're seeing above, a function that's called inside
  of a FixedUpdate().</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/GfOkC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GfOkC.jpg" alt="StateMachine"></a></p>
  
  <p>I've tried to set up the Animator State Machine but all animations would occur at the same time. That's when I abandoned the Animator and decided to call my animations to play from code. I feel as though I've set up the state machine properly as far as my transition lines are concerned. </p>
  
  <p>Ok, so I've set a Trigger for each transition line named "Activate". I revamped my code accordingly into this:</p>
  
  <pre><code> private Animator anim;
  
   void Start()
   {
      anim = gameObject.GetComponent&lt;Animator&gt;();
   {
  
   if (Mathf.Abs(player.velocity.x) &gt; 0  &amp;&amp; onFloor==true)
      {
  
          //ani.SetTrigger(walk.ToString());
          anim.ResetTrigger("Idle");
          anim.SetTrigger("Walk");
      }
      else if(Mathf.Abs(player.velocity.x) == 0  &amp;&amp; onFloor==true)
      {
  
          //ani.SetTrigger(idle.ToString());
          anim.ResetTrigger("Walk");
          anim.SetTrigger("Idle");
  
      }
  </code></pre>
  
  <p>However, this still doesn't fix my issues. For one, the animations do not play. Secondly, I cannot test to see whether or not my player will flip on the axis once playing. </p>
  
  <p>I'm getting a mild error in the console during runtime that say's the animations don't exist. I made sure that all animations are on the states inside of the animator. I also made sure that none of the animations are marked Legacy. </p>