Search Unity

Animation not showing

Discussion in 'Animation' started by Huwey, Mar 21, 2019.

  1. Huwey

    Huwey

    Joined:
    Mar 17, 2019
    Posts:
    29
    Ok, I want to start by saying that I'm extremely new to all of this. I have pieced things together that I have found online so the way things are setup might not be the best way to do it. However I am having an issue with my animation for walking to the right (MoveRight) doesn't work. This is for a top down 2d game. Here is what my animator looks like. I hope it's done correctly please be kind if it's not :(.

    upload_2019-3-20_22-1-14.png

    Also here is the coding that I pieced together to get it working.
    It does properly change from the idle animation and back on all but going right and at that point it continues showing the idle animation. I have went as far as to change the keys associated to the animation changes and deleting and making the animation again.
    I would be so confused as to why it isn't working if it wasn't for the fact that I setup the left and then copied and pasted the rest changing the key and animation associated to it.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerAnimation : MonoBehaviour
    6. {
    7.  
    8.     public Animator anim;
    9.     public float maxSpeed = 7;
    10.  
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.         anim = GetComponent<Animator>();
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         if (Input.GetKeyDown(KeyCode.LeftArrow))
    21.         {
    22.             anim.SetBool("MoveLeft", true);
    23.             anim.SetBool("MoveRight", false);
    24.             anim.SetBool("MoveUp", false);
    25.             anim.SetBool("MoveDown", false);
    26.             anim.SetBool("Idle", false);
    27.         }
    28.         if(Input.GetKeyUp(KeyCode.LeftArrow))
    29.         {
    30.             anim.SetBool("MoveLeft", false);
    31.             anim.SetBool("Idle", true);
    32.         }
    33.         if (Input.GetKeyDown(KeyCode.RightArrow))
    34.         {
    35.             anim.SetBool("MoveRight", true);
    36.             anim.SetBool("MoveUp", false);
    37.             anim.SetBool("MoveDown", false);
    38.             anim.SetBool("MoveLeft", false);
    39.             anim.SetBool("Idle", false);
    40.         }
    41.         if (Input.GetKeyUp(KeyCode.RightArrow))
    42.         {
    43.             anim.SetBool("MoveRight", false);
    44.             anim.SetBool("Idle", true);
    45.         }
    46.         if (Input.GetKeyDown(KeyCode.UpArrow))
    47.         {
    48.             anim.SetBool("MoveUp", true);
    49.             anim.SetBool("MoveRight", false);
    50.             anim.SetBool("MoveDown", false);
    51.             anim.SetBool("MoveLeft", false);
    52.             anim.SetBool("Idle", false);
    53.         }
    54.         if (Input.GetKeyUp(KeyCode.UpArrow))
    55.         {
    56.             anim.SetBool("MoveUp", false);
    57.             anim.SetBool("Idle", true);
    58.         }
    59.         if (Input.GetKeyDown(KeyCode.DownArrow))
    60.         {
    61.             anim.SetBool("MoveDown", true);
    62.             anim.SetBool("MoveRight", false);
    63.             anim.SetBool("MoveUp", false);
    64.             anim.SetBool("MoveLeft", false);
    65.             anim.SetBool("Idle", false);
    66.         }
    67.         if (Input.GetKeyUp(KeyCode.DownArrow))
    68.         {
    69.             anim.SetBool("MoveDown", false);
    70.             anim.SetBool("Idle", true);
    71.         }
    72.     }
    73.  
    74.     void FixedUpdate()
    75.     {
    76.  
    77.         if (Input.GetKey(KeyCode.UpArrow))
    78.         {
    79.             transform.Translate(Vector3.up * Time.deltaTime, Camera.main.transform);
    80.         }
    81.         else if (Input.GetKey(KeyCode.DownArrow))
    82.         {
    83.             transform.Translate(Vector3.down * Time.deltaTime, Camera.main.transform);
    84.         }
    85.         else if (Input.GetKey(KeyCode.RightArrow))
    86.         {
    87.             transform.Translate(Vector3.right * Time.deltaTime, Camera.main.transform);
    88.         }
    89.         else if (Input.GetKey(KeyCode.LeftArrow))
    90.         {
    91.             transform.Translate(Vector3.left * Time.deltaTime, Camera.main.transform);
    92.         }
    93.     }
    94. }

    EDIT:
    So I noticed this when opening the file I got the following errors in the Console

    Controller 'Player': Transition '' in state 'MoveDown' uses parameter 'MoveRight' which is not compatible with condition type.

    It shows this for all states. up, down, left, and idle

    I'm not sure what I should be looking at to fix this. Any suggestions?
     
    Last edited: Mar 23, 2019
  2. Huwey

    Huwey

    Joined:
    Mar 17, 2019
    Posts:
    29
    Anyone at all?