Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

Unityでキャラクターをアニメーションさせる

f:id:JHashimoto:20140223054708p:plain

UnityでGameObjectにTk 2D Sptite Animatorを適用し、キャラクターをアニメーションさせる方法を紹介します。

手順

アニメーションのフレームに使うSprite Collectionを作成する

フレームとは、アニメーションを構成する各静止画のことです。

まず、フレームに使うSprite Collectionを作成します。Sprite Collectionの作り方については、以前のエントリーを参照してください。

2D ToolkitのTk 2d Tiled SpriteにSpriteを設定する - プログラマーな日々
今回は2D ToolkitのTk 2d Tiled SpriteにSpriteを設定してみます。 ...

Sprite Animationのプレハブを作成する

Sprite Collectionを作成したら、Sprite Animationのプレハブを作成します。

f:id:JHashimoto:20140302130435p:plain

f:id:JHashimoto:20140302145634p:plain

プレハブが作成されました。

f:id:JHashimoto:20140302145857p:plain

Sprite Animationのエディターを起動する

f:id:JHashimoto:20140302150247p:plain

新しいClipを作成する

f:id:JHashimoto:20140302165558p:plain

Clipが作成されました。

f:id:JHashimoto:20140302165712p:plain

Sprite Animationの名前を付ける

f:id:JHashimoto:20140302172806p:plain

1つ目のフレームを設定する

f:id:JHashimoto:20140302173343p:plain

フレームを追加する

[+]をクリックして、必要なだけフレームを追加し、それぞれにSprite CollectionとSpriteを設定します。

f:id:JHashimoto:20140302174142p:plain

アニメーションの時間を設定する

[Play]/[Stop]でアニメーションがどのように動くか確認できます。確認しながら、時間を調整します。

f:id:JHashimoto:20140302174803p:plain

変更を確定する

変更を確定し、エディターを閉じます。

f:id:JHashimoto:20140302175123p:plain

Sprite Animatorの適用対象のGameObjectを作成する

GameObjectの作成方法は、以前のエントリーを参照してください。

UnityでGameObjectを作成する - プログラマーな日々

Tk 2d SptiteをGameObjectに適用する

f:id:JHashimoto:20140302191738p:plain

Tk 2D Spriteが適用されました。

f:id:JHashimoto:20140302192131p:plain

Sprite CollectionとSpriteを設定する

Tk 2d Spriteに、先ほど作成しておいたSprite CollectionとSpriteを設定します。

f:id:JHashimoto:20140302192509p:plain

Tk 2d Sptite Animator をGameObjectに適用する

Tk 2D Spriteと同じ要領で、[Add Component]からTk 2d Sprite Animatorを適用します。

Tk 2d Sptite AnimationをTk 2d Sptite Animatorに設定する

作成しておいたSprite AnimationのClipをSprite Animatorに設定します。

f:id:JHashimoto:20140302194028p:plain

再生する

ここまでできたら、再生してみます。

f:id:JHashimoto:20140302194229p:plain

画像なのでわかりませんが、アニメーションしています。