簡體   English   中英

Unity 4.x:如何在Mecanim中訪問AnimationState

[英]Unity 4.x: How to Access AnimationState in Mecanim

我在Unity 4.5.x中使用Mecanim動畫系統。 我在一個名為“ VictorSprite”的GameObject上有一個Animator組件,該組件有幾層,每層都有幾個AnimationState。

如何訪問每個AnimationState更改其屬性,特別是速度?

不幸的是,我可以找到的大多數文檔都已棄用,並且沒有提到Mecanim。 我也嘗試過此代碼:

AnimationState animState = GameObject.Find("VictorSprite").GetComponent<Animator>().animation["VictorTalk"]; 

但是,我收到此錯誤消息:

"MissingComponentException: There is no 'Animation' attached to the "VictorSprite" game object, but a script is trying to access it. You probably need to add a Animation to the game object "VictorSprite". Or your script needs to check if the component is attached before using it."

Unity 3.x動畫組件已棄用,在Unity 4.x中不再推薦使用。

ps我也嘗試了這段代碼,但是它沒有提供良好的功能:

AnimatorStateInfo animState = GameObject.Find("VictorSprite").GetComponent<Animator>().GetCurrentAnimatorStateInfo(2);

ps 2:基本上,我要在游戲對象的不同層中應用多個動畫,並且我希望能夠動態地暫停其中的一個。 將其權重設置為0並沒有幫助,因為它“重置”了動畫,而不是暫停。

加快,

    var animator = unityChan.GetComponent<Animator> ();
    animator.speed = 10.0f;

這應該給您您想要的。

Animator animator = GameObject.Find("ObjectInScene").GetComponent<Animator>();
AnimationInfo[] stateInfo = animator.GetCurrentAnimationClipState(index);

但是,尚不清楚您為什么真正想要這個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM