Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Animations Problems

Discussion in 'Animation' started by SwartExe, Jun 26, 2021.

  1. SwartExe

    SwartExe

    Joined:
    Jun 25, 2021
    Posts:
    7
    Hello. I have a problem to connect the animations and the inputs. Can you help me to fix it?

    This is the error:
    upload_2021-6-26_11-53-51.png


    This is my Animation Component:
    upload_2021-6-26_11-54-47.png


    And this is my code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CharacterMotor : MonoBehaviour
    6. {
    7.  
    8.     //Animation du perso
    9.     Animation animations;
    10.  
    11.     //Vitesse de deplacement du perso
    12.     public float runSpeed;
    13.     public float turnSpeed;
    14.  
    15.     //Inputs
    16.     public string inputFront;
    17.     public string inputBack;
    18.     public string inputLeft;
    19.     public string inputRight;
    20.  
    21.     public Vector3 jumpSpeed;
    22.     BoxCollider playerCollider;
    23.  
    24.     void Start()
    25.     {
    26.         animations = gameObject.GetComponent<Animation>();
    27.         playerCollider = gameObject.GetComponent<BoxCollider>();
    28.     }
    29.  
    30.     void Update()
    31.     {
    32.  
    33.         //Avant
    34.         if (Input.GetKey(inputFront))
    35.         {
    36.             transform.Translate(0, 0, runSpeed * Time.deltaTime);
    37.             animations.Play("CopRigged|2RunCop");
    38.         }
    39.  
    40.         //Arriere
    41.         if (Input.GetKey(inputBack))
    42.         {
    43.             transform.Translate(0, 0, -(runSpeed / 2) * Time.deltaTime);
    44.             animations.Play("CopRigged|2RunCop");
    45.         }
    46.  
    47.         //Rotation Gauche
    48.         if (Input.GetKey(inputLeft))
    49.         {
    50.             transform.Rotate(0, -turnSpeed, 0);
    51.         }
    52.  
    53.         //Rotation Droite
    54.         if (Input.GetKey(inputRight))
    55.         {
    56.             transform.Rotate(0, turnSpeed, 0);
    57.         }
    58.     }
    59. }
    I also test with the Animator Component but I can't get it to work. Thanks to help me.