1

こんにちは、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);
        }
    } 
}
4

2 に答える 2

0

2 つのアニメーションが同時に再生されている場合、その条件が 2 つのグラフの遷移として使用されていることを意味します。たとえば、あなたの idle_left --> run_left と idle_up --> run_up は確かに同じ遷移条件を持っています (Up == 1.0 だと思います)。アニメーションを独立させたい場合は、遷移条件が同じであってはなりません。

それが役に立てば幸い。

于 2015-12-05T04:25:08.257 に答える
0

プライベート アニメーター アニメーター。

// 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);

    }
}
于 2016-02-09T09:41:45.380 に答える