代码中的Unity Oculus gearVr自动行走错误

时间:2018-07-22 23:35:49

标签: c# unity3d virtual-reality oculus

伙计们,我正在Unity中为Gear Vr开发一个Vr App。我写了这段代码:

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;
        }



    }
}

运行代码后,出现以下错误: NullReferenceException:对象引用未设置为对象的实例 controller.Update()(位于Assets / controller.cs:26) Virtual Reality SDK Oculus初始化失败。

感谢ZZaim

0 个答案:

没有答案