LoginSignup
9
3

More than 5 years have passed since last update.

UnityでVRのAndroidアプリをビルドする方法

Last updated at Posted at 2016-12-01

ディップ Advent Calendarの2日目担当の大屋です。

普段はディップ株式会社でネイティブアプリエンジニアとして働いています。

先日、都内某所で開催されたVRイベントで初めてVR体験しました。
VR.png

イベントの最後にVR体験会があって運よく体験できたんですが、ヘッドセットをつけると目の前には見たことない世界が広がってました。

今日お話ししたいのはUnityでVRアプリ(Android)を簡単にビルドする話を紹介していきます。

VRの開発環境構築

まずは環境構築です。

仮想空間に物体配置

hoge.png

続いて、仮装空間に物を配置していきます。
今回配置したのは地面となる平面、中心に四角、Unityのマスコットキャラのユニティちゃんです。

平面上をランダムで移動する動作を追加する。

物体を配置できたら、独自スクリプトをキャラクタにセットします。
どのような処理をコーディングしているかというと、キャラクタが歩いていく行き先を乱数で平面上のどこかに設定して、5秒たったら再度設定して平面上を行ったり来たりするようにしています。

下のファイルはその時のコードとなります。

MoveControl
using UnityEngine;
using System.Collections;

public class MoveControl : MonoBehaviour {

    RaycastHit hit;
    Ray ray;
    NavMeshAgent agent;
    Animator animator;

    // Use this for initialization
    void Start () {
        agent = GetComponent<NavMeshAgent> ();
        animator = GetComponent<Animator> ();
        StartCoroutine (RePositionWithDelay());
    }

    IEnumerator RePositionWithDelay() {
        while (true) {
            SetRondomPosition ();
            yield return new WaitForSeconds (5);
        }
    }

    void SetRondomPosition() {
        float x = Random.Range (-5.0f, 5.0f);
        float z = Random.Range (-5.0f, 5.0f);
        Debug.Log ("X,Z: " + x.ToString("F2") + ", " + z.ToString("F2"));
        agent.SetDestination( new Vector3 (x, 0.0f, z));
        animator.SetFloat ("Speed", 0.2f);
    }

    // Update is called once per frame
    void Update () {
        if (agent.destination == transform.position) {
            animator.SetFloat ("Speed", 0.0f);
        }
    }
}

build and Run

最後に実行です。

UnityのFile>BuildSettingを選択して表示される画面でplatformにAndroidを選択してBuild&Runすればオッケーです。

スクリーンショット 2016-12-01 22.50.16.png

終わりに

今回、ご紹介したのはAndroidアプリでVRアプリの作る時のざっとした流れでした。
VR体験するには対応する携帯端末が必要だったり、VR用のヘッドセットが必要だったりしますが、とても身近な存在になりつつあるなと感じています。ご興味ある方是非やって見てください。

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