Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Problem with animation change on key press

Discussion in 'Animation' started by traktorius81, Aug 7, 2018.

  1. traktorius81


    Aug 7, 2018
    Hello, i'm beginner in unity, and i have a problem with changing animations on key press. "Žmogus" is idle, and when i press D the animation should change to "eina dešinėn" and when i release D it should go back to idle. The transition from "eina dešinėn" to idle works great, but the transition from id to "eina dešinėn" happens even without pressing D. Please help

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    5. public class judėjimas_animacija : MonoBehaviour {
    7.     Vector3 jgreitis =;
    8.     Vector3 jgreitis2 =;
    9.     public Vector3 gravitacija;
    10.     public Vector3 xasis;
    11.     public float yasis;
    12.     private Rigidbody2D zmogeliukas;
    13.     private SpriteRenderer spriteRenderer;
    14.     public Animator anim;
    16.     bool space;
    17.     bool nusileido;
    19.     // Use this for initialization
    20.     void Start()
    21.     {
    22.         zmogeliukas = GetComponent<Rigidbody2D>();
    23.         anim = GetComponent<Animator>();
    24.     }
    25.     void Update()
    26.     {
    27.         if (Input.GetKey(KeyCode.D))
    28.             transform.position += xasis * Time.deltaTime;
    29.             anim.SetTrigger("einad");
    30.         if (Input.GetKeyUp(KeyCode.D))
    31.             anim.SetTrigger("einada");
    32.         if (Input.GetButtonDown("Jump"))
    33.             space = true;
  2. traktorius81


    Aug 7, 2018
    This is a photo of animator

    Attached Files: