C# 动画师不包含;IsInTransition“;
基于此,有一个公共函数名为IsInTransition。但是为什么我不能使用它呢 当我尝试在MonoDevelop中编写代码时,自动完成无法工作,并且生成错误:C# 动画师不包含;IsInTransition“;,c#,unity3d,unity5,C#,Unity3d,Unity5,基于此,有一个公共函数名为IsInTransition。但是为什么我不能使用它呢 当我尝试在MonoDevelop中编写代码时,自动完成无法工作,并且生成错误: Assets/Scripts/CatAnimator.cs(32,18): error CS1061: Type `Animator' does not contain a definition for `isInTransition' and no extension method `isInTransition' of typ
Assets/Scripts/CatAnimator.cs(32,18): error CS1061:
Type `Animator' does not contain a definition for `isInTransition'
and no extension method `isInTransition'
of type `Animator' could be found.
Are you missing an assembly reference?
有什么想法吗
完整代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Animator : MonoBehaviour {
Animator myAnimator;
public float speed = 10.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
CharacterController controller;
float currSpeed, Param1;
bool Param2, Param3;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController> ();
myAnimator = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
Param1 = 0;
Param2 = false;
Param3 = false;
if (controller.isGrounded) {
//==
}
if (myAnimator.IsInTransition (0)) { //ERROR HERE...
}
}//==update
}//==class
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类动画师:单行为{
动画师我的动画师;
公共浮子速度=10.0f;
公共浮子跳跃速度=8.0f;
公共浮子重力=20.0f;
专用矢量3移动方向=矢量3.0;
字符控制器;
浮动速度,参数1;
布尔参数2,参数3;
//用于初始化
无效开始(){
controller=GetComponent();
myAnimator=GetComponent();
}
//每帧调用一次更新
无效更新(){
参数1=0;
参数2=假;
参数3=假;
if(controller.isground){
//==
}
如果(myAnimator.IsInTransition(0)){//此处出错。。。
}
}//==更新
}//==类
这里的问题是您正在创建一个名为Animator
的类。然而,Unity
已经提供了一个animator类。当您声明类型为Animator
(Animator myAnimator;
)的对象时,编译器会考虑您的类,而不是Unity
提供的类。并且在您的类中没有要使用的IsInTransition()
方法要解决此问题,只需将您的类重命名为
MyAnimator
。但代码是什么?@hr请稍等片刻,我将在Unity手册中补充说明:IAnimatorControllerPlayable.IsInTransition
。关于这一点,它还说:实验性的:这个API是实验性的,将来可能会被更改或删除。@Hristo所以这个已经删除了,但没有通知。我在2015年出版的书中输入了这段代码……你们班的另一个名字叫Animator
,你们正在班上创建一个对象Animator
。当您调用myAnimator.IsInTransition
时,实际上是在Animator
类中查找名为IsInTransition