回答編集履歴
1
StateMachineBehaviourによる方法を追記
answer
CHANGED
@@ -30,4 +30,30 @@
|
|
30
30
|
animator.ApplyBuiltinRootMotion();
|
31
31
|
}
|
32
32
|
}
|
33
|
-
```
|
33
|
+
```
|
34
|
+
|
35
|
+
## StateMachineBehaviourによるApply Root Motion切り替え
|
36
|
+
|
37
|
+
まず、当初の回答で追加したキャラクター用のスクリプトの`OnAnimatorMove`は削除してしまい、再び「歩行アニメーションを再生すれば前進し、ジャンプアニメーションを再生すれば上方へ跳び上がる」という状態にしておきます。
|
38
|
+
そして、下記のようなスクリプトを作り...
|
39
|
+
|
40
|
+
```lang-csharp
|
41
|
+
using UnityEngine;
|
42
|
+
|
43
|
+
public class PartialRootMotionDisabler : StateMachineBehaviour
|
44
|
+
{
|
45
|
+
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
46
|
+
{
|
47
|
+
animator.applyRootMotion = false;
|
48
|
+
}
|
49
|
+
|
50
|
+
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
51
|
+
{
|
52
|
+
animator.applyRootMotion = true;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
```
|
56
|
+
|
57
|
+
それをApply Root Motionオフ状態にしたいステートにアタッチします。これならいかがでしょうか。
|
58
|
+
|
59
|
+

|