【发布时间】:2017-03-02 15:19:28
【问题描述】:
我正在使用 Gear VR 创建一个项目,您可以在其中旋转对象并根据耳机侧面的滑动和点击控件显示信息。
一切都很好,当我使用 Gear VR 侧面的触摸板时,我可以旋转和选择东西,但是当我改变场景并返回主菜单,然后回到我刚刚打开的场景时,该功能停止工作。
我正在使用我制作的这个脚本:
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using System;
public class GearVRTouchpad : MonoBehaviour
{
public GameObject heart;
public float speed;
Rigidbody heartRb;
void Start ()
{
OVRTouchpad.Create();
OVRTouchpad.TouchHandler += Touchpad;
heartRb = heart.GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
SceneManager.LoadScene("Main Menu");
}
}
void Touchpad(object sender, EventArgs e)
{
var touches = (OVRTouchpad.TouchArgs)e;
switch (touches.TouchType)
{
case OVRTouchpad.TouchEvent.SingleTap:
// Do some stuff
break;
case OVRTouchpad.TouchEvent.Up:
// Do some stuff
break;
//etc for other directions
}
}
}
我注意到当我开始我的游戏时,会创建一个OVRTouchpadHelper。我不知道这是否与我的问题有关。
我得到的错误是:
MissingReferenceException: The object of type 'GearVRTouchpad' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
但是我没有在其他任何地方引用过这个脚本。
当我在播放模式下检查我的场景时,脚本仍然存在,变量分配仍然存在。
任何帮助都会很棒!
【问题讨论】:
-
您的错误不在 GearVRTouchpad 类中,而是在使用 GearVRTouchpad 的类中。如果你能提供那些抛出这个异常的东西会很好。
-
我认为可能是这种情况,但我没有在任何其他脚本或文件中使用过这个脚本?
标签: c# unity3d virtual-reality gear-vr