LoginSignup
3
4

More than 5 years have passed since last update.

Mecanimで単純なアニメーション

Last updated at Posted at 2014-08-31

Mayaでキーフレームアニメーションをつけた後、FBX形式などで書き出したものを Unityに取り込んだらInspectorのAnimationsタブからClipsでアニメーションのキーフレームを設定します。
※両側のオブジェクトが開いたり閉じたりするアニメーションをつくりました。

スクリーンショット 2014-09-01 1.59.34.png

スクリーンショット 2014-09-01 1.55.23.png

Hierarchryにモデルデータをドラック&ドロップしたらAddComponentからAnimatorを選択します。
Animation Controllerを作り、Controllerにアサインします。

スクリーンショット 2014-09-01 2.03.03.png

AキーとSキーを押す事でモデルが開いたり閉じたりするアニメーションをするようにAnimatorを設定します。
静止しているアニメーション
開く、閉じるのアニメーションと4つのStateで構成しました。
アニメーション間の管理は、ParametersのBoolにしています。
これ超便利です。

スクリーンショット 2014-09-01 1.55.03.png

スクリプトは以下のようにしました。
超シンプルで簡単です。

using UnityEngine;
using System.Collections;

public class MecanimTest : MonoBehaviour {
    Animator animator;
    void Awake(){
        animator = GetComponent<Animator> ();
    }
    void Start () {
        animator.SetBool ("open_bool", false);  
    }
    void Update () {
        if (Input.GetKey ("a")) {
            animator.SetBool ("open_bool", true);
        } else if (Input.GetKey ("s")) {
            animator.SetBool ("open_bool", false);
        }
    }
}

これで、以下のような感じで開閉させました。
スクリーンショット 2014-09-01 1.54.35.png

スクリーンショット 2014-09-01 1.54.26.png

3
4
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
3
4