Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Anonymous's avatar
Anonymous
7 years ago
Approved

Unity Oculus gearVr Auto walking error in code

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

Replies have been turned off for this discussion