动画师不包含 "IsInTransition"

Animator does not contain "IsInTransition"

基于此 Unity Animator API,有一个名为 IsInTransition 的 public 函数。但为什么我不能使用它?

当我尝试在 MonoDevelop 中编写代码时,Autocompletion 无法正常工作并且构建时出现错误:

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

这里的问题是您正在制作一个名为 Animator 的 class。但是 Unity 已经提供了一个动画师 class。当您声明类型为 Animator (Animator myAnimator;) 的对象时,编译器会考虑您的 class 而不是 Unity 提供的 class。在你的 class 中没有 IsInTransition() 方法可以使用。
要解决此问题,只需将 class 重命名为 MyAnimator 即可。