Unity3D Blenderで作成したアニメーションをUnityで利用
①Blenderでアニメーションを作成
無い場合はテスト用のこちらをダウンロード→テストアニメーション
②Unity3Dでプロジェクトを作成し、「Assets」⇒「Imposrt New Asset」を押下し、①で作成したモデルをインポート
③モデルを右クリックし、「Create」⇒「Animator Controller」を押下し、適当な名前を付ける
④作成した「Animator Controller」をダブルクリック⇒「Create State」⇒「Empty」を押下して新しいStateを作成
⑤「+」⇒「Bool」を押下し、適当な名前をつける
⑥④で作成したStateにAnimationをインスペクタにドラッグ
⑦①でインポートしたモデルを「ヒエラルキーウィンドウ」にドラッグ⇒インスペクタの「Controller」にドラッグ
⑧下記内容でスクリプトを作成
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Action : MonoBehaviour
{
// アニメーターオブジェクトを宣言
Animator animator;
// Start is called before the first frame update
void Start()
{
// アニメーターオブジェクトをセット
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
// スペースを押下時
if (Input.GetKey(KeyCode.Space)) {
// アニメーションを起動するフラグをONにして、アニメーターにセット
animator.SetBool("flag", true);
}
}
}
⑨⑧で作成したスクリプトをヒエラルキーウィンドウのモデルにセット
⑩スペースを押下するとモデルのアニメーションが作動する
※メインカメラが思い通りに機能しない場合はモデルに初期セットされているカメラは邪魔になるのでインスペクからチェックを外す