Unity C#Animator Transitions

时间:2015-06-16 19:49:23

标签: c# animation unity3d transitions animator

我试图让我的敌人在他移动时运行动画播放,并在他停止时切换回空闲状态。但是我现在的代码似乎并没有这样做,而是我的敌人不断地处于空闲状态。我已经检查过我的变量正在设置但是它们似乎没有被过滤到我的动画制作器进行转换。我也有一个错误似乎并没有停止游戏,而是在控制台弹出。错误是Controller 'Pirate': Transition " in state 'Idle_Pirate' uses parameter 'walking' which is not compatible with condition type.我认为这是罪魁祸首但是在谷歌搜索了一些不同的建议后,我正在努力寻找解决方案。这是附加到敌人脚本的代码。道歉,如果它有点粗糙,我还在学习。非常感谢任何帮助。

using UnityEngine;
using System.Collections;

public class AI : MonoBehaviour {

    public float walkSpeed = 2.0f;
    public float wallLeft = 0.0f;
    public float wallRight = 2.0f;

    float walkingDirection = 1.0f;
    Vector3 walkAmount;
    float timeCheck = 0.0f;
    float walkCheck = 0.0f;

    public float maxSpeed = 5f;
    bool facingRight = true;
    bool idle = true;

    Animator anim;

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

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



    }

    void Update () {
        if (timeCheck >= 2.0f) {
            walkAmount.x = walkingDirection * walkSpeed * Time.deltaTime;
            if (walkingDirection > 0.0f && transform.position.x >= wallRight) {
                walkingDirection = -1.0f;
                Flip ();
            } else if (walkingDirection < 0.0f && transform.position.x <= wallLeft) {
                walkingDirection = 1.0f;
                Flip ();
            }
            walkCheck = walkCheck + Time.deltaTime;
            idle = false;
        }

        if (walkCheck >= 2.0f) {
            idle = true;
            walkAmount.x = 0;
            timeCheck = 0.0f;
            walkCheck = 0.0f;
        }

        timeCheck = timeCheck + Time.deltaTime;
        transform.Translate(walkAmount);
        anim.SetBool ("walking", idle);

    }

    void Flip () {

        facingRight = !facingRight;
        Vector3 theScale = transform.localScale;
        theScale.x *= -1;
        transform.localScale = theScale;

    }
}

1 个答案:

答案 0 :(得分:0)

无论如何管理自己想出来,原来我在我的动画师中使用我的动画而不是我的精灵,必须在某些时候拖出错误的东西。感谢那些花时间阅读的人。