質問編集履歴

1

質問を変更

2020/08/22 08:37

投稿

javascripter
javascripter

スコア12

test CHANGED
@@ -1 +1 @@
1
- unity のGetCurrentAnimatorにつて教えてください
1
+ unity のAnimationStateでモーションの現在時間を読み取れな
test CHANGED
@@ -1,55 +1,35 @@
1
- unityでアニメーションをスクリプトから制御よう思い勉強しているのですが、GetCurrentAnimatorについての解説ページが無くて困っています。
1
+ ### 前提・実現たいこ
2
2
 
3
- モーションの現在フレームの取得、フレームの大きさなどの取得にGetCurrentAnimatorが必要なようで、解説が欲しいです。
3
+ https://docs.unity3d.com/ja/current/ScriptReference/AnimationState.html
4
4
 
5
- ```c#
5
+ ここによると、AnimationStateでtimeは現在のアニメーション時間ということで利用したい。
6
6
 
7
7
 
8
8
 
9
- public class TestAnimation : MonoBehaviour
10
-
11
- {
12
-
13
- private Animator m_animator;
9
+ ### 発生している問題・エラーメッセージ
14
10
 
15
11
 
16
12
 
17
- void Awake()
13
+ 以下のコードで実行すると
18
-
19
- {
20
-
21
- m_animator = GetComponent< Animator >();
22
-
23
- }
24
14
 
25
15
 
26
16
 
27
- public void SetAnimationFrame( int i_frame )
28
-
29
- {
30
-
31
- var clipInfoList = m_animator.GetCurrentAnimatorClipInfo( 0 );
32
-
33
- var clip = clipInfoList[ 0 ].clip;
17
+ 'Animation' does not contain a definition for 'speed' and no accessible extension method 'speed' accepting a first argument of type 'Animation' could be found (are you missing a using directive or an assembly reference?)
34
18
 
35
19
 
36
20
 
37
- float time = (float)i_frame / clip.frameRate;
21
+ とエラーが出てしまう。(多分定義されていないといわれている?)
38
22
 
39
23
 
40
24
 
41
- var stateInfo = m_animator.GetCurrentAnimatorStateInfo( 0 );
25
+ ### 該当のソースコード
42
26
 
43
- var animationHash = stateInfo.shortNameHash;
27
+ 定義は省きます。また、modelはインスペクターにアニメーションを設定したゲームオブジェクトです。
44
28
 
29
+ ```C#
45
30
 
31
+ animation = model.GetComponentInChildren<Animation>();
46
32
 
47
- m_animator.Play( animationHash, 0, time );
33
+ Debug.Log(animation.time);
48
-
49
- }
50
-
51
- }
52
-
53
-
54
34
 
55
35
  ```