Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. 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

    traktorius81

    Joined:
    Aug 7, 2018
    Posts:
    2
    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;
    4.  
    5. public class judėjimas_animacija : MonoBehaviour {
    6.  
    7.     Vector3 jgreitis = Vector3.zero;
    8.     Vector3 jgreitis2 = Vector3.zero;
    9.     public Vector3 gravitacija;
    10.     public Vector3 xasis;
    11.     public float yasis;
    12.     private Rigidbody2D zmogeliukas;
    13.     private SpriteRenderer spriteRenderer;
    14.     public Animator anim;
    15.  
    16.     bool space;
    17.     bool nusileido;
    18.  
    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;
    34.  
     
  2. traktorius81

    traktorius81

    Joined:
    Aug 7, 2018
    Posts:
    2
    This is a photo of animator
     

    Attached Files: