2017-06-01 87 views
1

基於此Unity Animator API,有一個名爲IsInTransition的公共函數。但爲什麼我不能使用它?動畫師不包含「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

但是最新的代碼? – Hristo

+0

@Hristo等一下,我會加上 – anunixercoder

+0

它在Unity手冊中說:'IAnimatorControllerPlayable.IsInTransition'。還有它說:_實驗:這個API是實驗性的,可能會在將來更改或刪除。 – Hristo

回答

2

這裏的問題是,你正在一個名爲Animator類的事實。但是有一個動畫師課程已經由Unity提供。當您聲明類型AnimatorAnimator myAnimator;)的對象時,編譯器會考慮您的類而不是Unity提供的類。並且在你的班級中沒有使用IsInTransition()方法。
要解決這個問題,只需將您的班級重命名爲MyAnimator即可。