【问题标题】:Unity C# Animator TransitionsUnity C# 动画转换
【发布时间】:2015-06-16 19:49:23
【问题描述】:

我试图让我的敌人在他移动时播放动画,并在他停止时切换回空闲状态。但是,我当前的代码似乎并没有这样做,而是我的敌人一直处于空闲状态。我已经检查了我的变量是否正在设置,但它们似乎并没有被我的动画师过滤以进行转换。我还有一个错误,似乎并没有阻止游戏播放,而是在控制台中弹出。错误是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;

    }
}

【问题讨论】:

  • Unity3D 的正确标签是unity3d
  • 啊,我明白了,我的错,下次注意!谢谢。

标签: c# animation unity3d transitions animator


【解决方案1】:

无论如何我自己设法弄清楚了,结果我在我的动画师中使用我的动画而不是我的精灵,一定是在某些时候拖了错误的东西。感谢那些花时间阅读的人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多