C# unity animator中的anim.SetBool(“IsWalking”,walking)错误

C# unity animator中的anim.SetBool(“IsWalking”,walking)错误,c#,unity3d,C#,Unity3d,在团结学习部分-生存射击,我得到一个错误显示以下错误 类型“UnityEngine.Animation”不包含“SetBool”的定义,并且找不到类型为“UnityEngine.Animation”的扩展方法“SetBool”。是否缺少程序集引用 我已经检查了文件和组件的名称 代码 使用UnityEngine; 公共类玩家运动:单一行为 { 公共浮子速度=6f; 矢量3运动; 动画; 刚体播放器刚体; int floorMask; 浮动凸轮轴长度=100f; 无效唤醒() { floorMask

在团结学习部分-生存射击,我得到一个错误显示以下错误

类型“UnityEngine.Animation”不包含“SetBool”的定义,并且找不到类型为“UnityEngine.Animation”的扩展方法“SetBool”。是否缺少程序集引用

我已经检查了文件和组件的名称

代码
使用UnityEngine;
公共类玩家运动:单一行为
{
公共浮子速度=6f;
矢量3运动;
动画;
刚体播放器刚体;
int floorMask;
浮动凸轮轴长度=100f;
无效唤醒()
{
floorMask=LayerMask.GetMask(“地板”);
anim=GetComponent();
playerRigidbody=GetComponent();
}
void FixedUpdate()
{
float h=Input.GetAxisRaw(“水平”);
float v=Input.GetAxisRaw(“垂直线”);
移动(h,v);
转动();
动画(h,v);
}
无效移动(浮动h、浮动v)
{
运动设定(h、0f、v);
移动=移动。标准化*速度*时间。延迟时间;
playerRigidbody.MovePosition(transform.position+movement);
}
空转()
{
Ray camRay=Camera.main.ScreenPointRoay(输入.鼠标位置);
瑞卡斯特;
if(Physics.Raycast(camRay、out floorHit、camRayLength、floorMask))
{
Vector3 playerToMouse=floorHit.point-transform.position;
playerToMouse.y=0f;
四元数newRotation=四元数LookRotation(playertomuse);
playerRigidbody.MoveRotation(新旋转);
}
}
无效动画(浮动h、浮动v)
{
布尔步行=h!=0f | | v!=0f;
动画挫折(“IsWalking”,walking);
}
}

角色的动画控制器的类型为
Animator
,而不是
animation
。使用
Animator
上的
SetBool

Animator anim;

void Awake()
{
    // ...
    anim = GetComponent<Animator>();
    // ...
}
动画师动画;
无效唤醒()
{
// ...
anim=GetComponent();
// ...
}

读取错误消息。错误消息让我问您:为什么您认为
动画
对象(您的动画是动画类型的对象)具有
SetBool
方法?检查文档中的
动画类型:。你能看到它有一个SetBool方法吗?
Animator anim;

void Awake()
{
    // ...
    anim = GetComponent<Animator>();
    // ...
}