LoginSignup
16
12

More than 3 years have passed since last update.

ユニティちゃんを動かす

Last updated at Posted at 2020-10-28

似たような記事はゴマンとあるけど、毎回どうだったけー?と悩むので、自分用の備忘録として綴ることにする。

動作確認バージョン

Unity 2019.4.13f1

まず

Unityをたちあげ、新規で3Dのプロジェクトを開く。

地面を配置。
Hierarchy > 3DObject > Plane
Image from Gyazo

AssetStoreから
Unity-Chan!Model
をダウンロード&インポートする。

Image from Gyazo

Project > Asset >UnityChan! > UnityChan!Model > Prefabs
にあるunitychan_dynamic をシーンにドラッグする。
(2つユニティちゃんのPrefabがあるが、dynamicの方が新しいらしいので、dynamicにした)
Image from Gyazo

Play

Image from Gyazo

おっと、
ユニティちゃんが後ろ向きなので、RotationのYを180にセット。
Image from Gyazo

再度、Playすると、正面向いた。
Image from Gyazo

UNityちゃんを選択した状態で
inspector > Add Component
RigidbodyとCapsule Colliderを追加

Image from Gyazo

使わないので、
unitychanのInspectorの Idle Changer、Face Update、Auto Blinkのチェックをはすず。(または削除する)

アニメーション

Project > Asset >UnityChan! > UnityChan!Model > Art > Animations > Animators

project +
Animation Controller

できたファイルをクリック

名前を Walkとする。(なんでもいい)

こんな画面

Image from Gyazo

画面を右クリック
Create State > Empty

New State があらわれる
Image from Gyazo

名前を Idle に変更し、
Motionを WAIT00を選ぶ (なんでもいいけど)

Image from Gyazo

新しく
画面を右クリック
Create State > Empty

名前をWalk、MotionをWALK00_F

Image from Gyazo

IdleとWalkの間に双方向の矢印
(右クリック Make Transition)

Image from Gyazo

parameterの右下にある +をクリック
Image from Gyazo

Boolを選択

Idel -> Walkの 矢印をアクティブにしたまま、

1、名前を is_walking、
2、Has Exit Timeのチェックを外す
(なぜかわからないけど、チェックがあると、スムーズに歩き出さない)
3、conditions を is_walking trueに

Image from Gyazo

Walk -> Idle の
conditions を is_walking falseに

Image from Gyazo

UnityChanの Inspectorの
Animator > Controller を
先ほど作った Walkに
Image from Gyazo

スクリプト

Walk.cs

using UnityEngine;
using System.Collections;

public class Walk : MonoBehaviour
{

    private Animator animator;
    // Use this for initialization
    void Start()
    {
        animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey("up"))
        {
            transform.position += transform.forward * 0.005f;
            animator.SetBool("is_walking", true);
        }
        else if(Input.GetKey("down"))
        {
            transform.position -= transform.forward * 0.005f;
            animator.SetBool("is_walking", true);
        }
        else
        {
            animator.SetBool("is_walking", false);
        }
        if (Input.GetKey("right"))
        {
            transform.Rotate(0, 0.2f, 0);
        }
        if (Input.GetKey("left"))
        {
            transform.Rotate(0, -0.2f, 0);
        }
    }



}

このスクリプトをUnityChanにアタッチする。

Image from Gyazo

プレイ

ユニティちゃんが、キー操作で歩いた!
Image from Gyazo

カメラ追随

メインカメラをUnityChanの子オブジェクトにする。

Image from Gyazo

カメラの位置を合わせる。
Rotaionも合わせたらいいと思う。(これは ROTAION X:10, Y:0, Z:0)
Image from Gyazo



できた。

Image from Gyazo

16
12
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
16
12