基于此Unity Animator API,有一个名为 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 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
答案 0 :(得分:2)
这里的问题是你正在创建一个名为Animator
的类。但是Unity
已经提供了一个动画类。当您声明类型为Animator
(Animator myAnimator;
)的对象时,编译器会考虑您的类而不是Unity
提供的类。在您的课堂上,没有IsInTransition()
方法可供使用。
要解决此问题,只需将您的班级重命名为MyAnimator
即可。