角色动画师问题动画无法正常工作

Character animator issue animation not working correctly

你好,我正在使用 unity 开发一个迷你 2d 游戏,我只是创建了一个 2d 角色和一些动画 (Up_Idle,Down_Idle,Right_Idle,Left_Idle/Up_run, Down_run,Right_run,Left_run) 问题是这些动画无法正常工作(例如,当我按下向上箭头时,角色没有播放 Up_run 动画,但他同时播放 Up_run 和 left_run 动画)

这里是截图:

代码如下:

using UnityEngine;
using System.Collections;

public class movement : MonoBehaviour
{

    public float speedX =1f;

    public float speedY =1f;

    Animator animator;

    void Start()
    {
        animator = GetComponent <Animator> ();
    }

    void Update()
    {
        if (Input.GetKey (KeyCode.UpArrow)) {
                    transform.Translate (new Vector2 (speedX, speedY) * Time.deltaTime);
                    animator.SetFloat ("Up", 1);
                    return;
        } else {
            animator.SetFloat ("Up", 0);
        }

        if (Input.GetKey (KeyCode.DownArrow)) {
            transform.Translate (new Vector2 (-speedX, -speedY) * Time.deltaTime);
            animator.SetFloat ("Down", 1);
            return;

        } else {
            animator.SetFloat ("Down", 0);
        }

        if (Input.GetKey (KeyCode.RightArrow)) {
            transform.Translate (new Vector2 (speedX, -speedY) * Time.deltaTime);
            animator.SetFloat ("Right", 1);
            return;
        } else {
            animator.SetFloat ("Right", 0);
        }

        if (Input.GetKey (KeyCode.LeftArrow)) {
            transform.Translate (new Vector2 (-speedX, speedY) * Time.deltaTime);
            animator.SetFloat ("Left", 1);
            return;
        } else {
            animator.SetFloat ("Left", 0);
        }
    } 
}

如果同时播放两个动画,则表示该条件用作2个图形的过渡。例如,您的 idle_left --> run_left 和 idle_up --> run_up 具有相同的转换条件(我假设为 Up == 1.0)。如果你想让动画独立,它们不应该有相同的过渡条件。

希望对您有所帮助。

private Animator动画师;

// Use this for initialization
void Start()
{
    animator = this.GetComponent<Animator>();

}

// Update is called once per frame
void Update()
{

    var vertical = Input.GetAxis("Vertical");
    var horizontal = Input.GetAxis("Horizontal");

    if (vertical > 0)
    {
        animator.SetInteger("Direction", 1);
         transform.Translate(Vector2.up* Time.deltaTime);
        //animator.SetInteger("Direction", 2);
        animator.SetFloat("Speed", 1.0f);
    }
    else if (vertical < 0)
    {
        animator.SetInteger("Direction", 3);
        transform.Translate(Vector3.down* Time.deltaTime);
        //animator.SetInteger("Direction", 0);
        animator.SetFloat("Speed", 1.0f);
    }
    else if (horizontal < 0)
    {
        animator.SetInteger("Direction", 4);

          transform.Translate(Vector3.left* Time.deltaTime);

        //transform.Translate(Vector2.right* Time.deltaTime);
        animator.SetFloat("Speed", 1.0f);
    }
    else if (horizontal > 0)
    {

    animator.SetInteger("Direction", 2);
    transform.Translate(Vector2.right* Time.deltaTime);
     // animator.SetInteger("Direction", 4);
    animator.SetFloat("Speed", 1.0f);
    }
    else
    {
      //animator.SetInteger("Direction", 6);
        animator.SetFloat("Speed", 0.0f);

    }
}