LoginSignup
2
1

More than 5 years have passed since last update.

FirstVRでリセンターを実装する

Posted at

前回の記事で、FirstVRにもともと実装されているリセンター機能について説明しました。

今回は、このリセンター機能をボタンに実装してみようと思います。

SDKのダウンロード等の説明は、前回の記事を参照してください。

実装

FVR/Samples/Scenesの中のOutputViewerを開きます。

今回もわかりやすいように、Cubeを手に入れ替えました。
スクリーンショット 2018-11-16 19.09.02.png

SceneManagerにアタッチされているSampleViewerManager.csを以下のように書き換えます。

SampleViewerManager.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using FVRlib;

public class SampleViewerManager : MonoBehaviour {

    // FVR 
    public FVRConnection fvr;

    // vars
    public GameObject hand;
    bool touched = false;

    void Start () {
        hand = GameObject.Find("Hand_right");
    }


    void Update () {
        hand.transform.rotation = fvr.centeredRotation;

        /*** 以下をコメントアウト ***/
        //if (Input.touchCount == 1&&!touched) {
        //  fvr.Recenter ();
        //  touched = true;
        //}
        //if (Input.touchCount == 0&&touched) {         
        //  touched = false;
        //}
        /*** ここまでコメントアウト ***/
    }

    /*** 以下を追加 ***/
    public void RecenterButton(){
        fvr.Recenter();
    }
    /*** ここまで追加 ***/
}

コードを書き換えたら、シーンにボタンを設置します。

スクリーンショット 2018-11-16 19.52.44.png

スクリーンショット 2018-11-16 19.12.50.png

設置したら、ButtonオブジェクトのInspectorにあるOn Click()に項目を追加します。
SceneManagerをアタッチし、SampleViewerManager > RecenterButton()を選択します。
スクリーンショット 2018-11-16 19.18.25.png

これで、実装完了です。

実機確認

スマホで実行してみると、こんな感じになります。
IMG_0056.TRIM.gif

2
1
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
2
1