Search Unity

Gear Vr Autowalking code

Discussion in 'VR' started by Zaid_Zaim, Jul 24, 2018.

  1. Zaid_Zaim

    Zaid_Zaim

    Joined:
    Jul 21, 2018
    Posts:
    2
    Hey guys I am developing a Vr App in Unity for gear Vr. I am using Unity 2018.2.0f2 (64bit) on mac. This is My Oculus SDK: oculussig_ce12160c34e98e2301 . I wrote this code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class controller : MonoBehaviour {
    public GameObject ground;
    private bool walking= false;
    private Vector3 spawnPoint;


    // Use this for initialization
    void Start () {
    spawnPoint = transform.position;
    }

    // Update is called once per frame
    void Update () {
    if (walking){
    transform.position = transform.position + Camera.main.transform.forward * .5f * Time.deltaTime;
    }

    if (transform.position.y<-10f){
    transform.position = spawnPoint;

    }
    //The compiler is giving the error here
    Ray ray = Camera.main.ViewportPointToRay(new Vector3(.5f, .5f,0));
    //^
    RaycastHit hit;

    if(Physics.Raycast(ray,out hit)){
    walking = false;
    } else{
    walking = true;
    }



    }
    }
    After I run the code I get these Errors: NullReferenceException: Object reference not set to an instance of an object controller.Update () (at Assets/controller.cs:26) Virtual Reality SDK Oculus failed to initialize.



    Thanks in advance ZZaim