移除耳机后,我正在尝试切换到另一个场景。它已经在 Unity 编辑器中工作,但是,不在构建中。
设置:
- 统一2018.3.6f1
- SteamVR Unity 插件 v.2.2.0
- 万岁临
此代码在编辑器中工作:
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using Valve.VR;
public class EndGame : MonoBehaviour
{
[Tooltip("This action lets you know when the player has placed the headset on their head")]
public SteamVR_Action_Boolean headsetOnHead = SteamVR_Input.GetBooleanAction("HeadsetOnHead");
void Update()
{
if (SteamVR.initializedState != SteamVR.InitializedStates.InitializeSuccess)
{
return;
}
if (headsetOnHead != null)
{
if (headsetOnHead.GetStateDown(SteamVR_Input_Sources.Head))
{
StopCoroutine(RestartGame());
}
else if (headsetOnHead.GetStateUp(SteamVR_Input_Sources.Head))
{
StartCoroutine(RestartGame());
}
}
}
IEnumerator RestartGame()
{
yield return new WaitForSecondsRealtime(3);
SceneManager.LoadScene("Startscene", LoadSceneMode.Single);
yield return null;
}
}
在编辑器中,\actions\default\in\HeadsetOnHead 引用了公共 SteamVR_Action_Boolean 耳机 OnHead。
actions.json(包括 /actions/default/in/HeadsetOnHead)位于 build 文件夹中,并且日志不显示任何错误。