4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Mecanim をなるべく使わない Animator メモ

Last updated at Posted at 2021-04-24

方法

image.png
Mecanim に State を並べて配置し、スクリプトから State名 を指定してアニメーションさせる。

再生・停止

//再生
animator.Play("Run");
//一時停止
animator.speed = 0f;
//続きから再生
animator.speed = 1f;
//はじめから再生
animator.Play("Jump", レイヤー番号, 0 (開始地点) );

遷移

animator.CrossFade("Run", 遷移時間, レイヤー番号, 遷移先の開始時間 );

ブレンド

レイヤーで疑似的にブレンドできるが管理が大変になるため、BlendTree を推奨する。

//BlendTree を使う際のスクリプト
animator.Play("Run");
animator.SetFloat("Speed", 割合 );

//レイヤーを使う際のスクリプト
animator.Play("Walk");
animator.Play("Run", レイヤー番号 );
animator.SetLayerWeight( レイヤー番号, 割合 );

レイヤーについて

image.png

項目名 説明
Weight 合成の割合
Mask 部位ごとにアニメーションを上書き・加算
Blending 合成方法
Sync 指定したレイヤーと State 群を同期し、アニメーションのみ変更する。状態異常で全体のアニメーションを変更したい時などに有用。
Timing アニメーションの長さを調整可能にする
IK Pass コールバック関数「OnAnimatorIK(int layerIndex)」が呼ばれるようになる。animator.SetIK○○ 関数を使って動的にアニメーションを変更できる。

レイヤー番号は上から昇順で指定する。Base Layer は 0、UpperBody は 1。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?