Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未在Unity 5.3.5f1中播放的动画_C#_Unity3d - Fatal编程技术网

C# 未在Unity 5.3.5f1中播放的动画

C# 未在Unity 5.3.5f1中播放的动画,c#,unity3d,C#,Unity3d,由于某些原因,我的动画没有播放,它看起来像卡在第一帧上 public Animator anim; void FixedUpdate () { targetDistance = Vector3.Distance(target.position, transform.position); if (targetDistance < attackDistance) { attack(); print("Attack");

由于某些原因,我的动画没有播放,它看起来像卡在第一帧上

public Animator anim;
void FixedUpdate () {
    targetDistance = Vector3.Distance(target.position, transform.position);


    if (targetDistance < attackDistance)
        {

        attack();
        print("Attack");
    }
}
void attack()
{
    theRigidBody.AddForce(transform.forward * speed);

    anim.Play("attack", -1, 0f);
}
公共动画师动漫;
无效固定更新(){
targetDistance=矢量3.距离(target.position,transform.position);
if(目标距离<攻击距离)
{
攻击();
打印(“攻击”);
}
}
无效攻击()
{
theRigidBody.AddForce(transform.forward*速度);
动画游戏(“攻击”,-1,0f);
}

它正在控制台中打印“攻击”,生物会改变姿势,但由于某种原因它不会播放。

您是否在编辑器中设置了动画变量?否则可能会导致错误,所以您可能会这样做

试试这个:

anim.Play("attack", PlayMode.StopAll); 
//or
anim.Play("attack", PlayMode.StopSameLayer);
如果没有成功,请执行以下操作:

print(anim.Play("attack", PlayMode.StopAll).ToString());

如果返回false,则表示未找到名为“攻击”的动画。

这是Unity 5.3中的遗留问题