Forum Discussion
Anonymous
7 years agoUnity 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
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 4 months ago
- 1 month ago
- 4 years ago
- 1 year ago
- 3 years ago