01-25-2020 03:00 PM
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MenuPauseControl : MonoBehaviour
{
public GameObject OVRCameraRig;
public GameObject Canvas;
public GameObject EventSystem;
void Start()
{
}
void Update()
{
if (OVRManager.hasInputFocus && OVRManager.hasVrFocus)
{
ContinueGame();
}
else
{
PauseGame();
}
}
private void PauseGame()
{
Time.timeScale = 0;
//Disable stuff that still work while timescale is set to 0
OVRCameraRig.SetActive(false);
Canvas.SetActive(false);
EventSystem.SetActive(false);
}
private void ContinueGame()
{
Time.timeScale = 1;
//enable the stuff again
OVRCameraRig.SetActive(true);
Canvas.SetActive(true);
EventSystem.SetActive(true);
}
}
and here's my hierarchy:01-26-2020 09:12 AM
//pause if in oculus home universal menu, and if headset not worn
bool bPauseNow = (!OVRManager.hasInputFocus || !OVRManager.hasVrFocus) /*|| (XRDevice.userPresence!=UserPresenceState.Present)*/;
//pause state change
if (bPause != bPauseNow)
{
bPause = bPauseNow;
if (bPauseNow)
{
Time.timeScale = 0.0f; //stops FixedUpdate
//also need to stop all sound
AudioListener.pause = true;
AudioStateMachine.instance.masterVolume = 0.0f;
}
else
{
Time.timeScale = 1.0f;
AudioListener.pause = false;
AudioStateMachine.instance.masterVolume = 1.35f;
}
}
01-26-2020 09:29 AM
01-26-2020 09:39 AM
01-26-2020 11:14 AM
03-17-2021 03:25 PM
Hi rh_galaxy,
I'm also failing my VR.PC.Functional.3, VR.PC.Input.2 & VR.PC.Input.3 and Oculus tech pointed me to this page.
Your code looks great, however, I am new to State Machines.
How are you declaring bPause and AudioStateMachine? Are these ints or floats? Public or Private?
Thanks so much!
10-17-2023 02:34 AM
Hi everyone, i ran into the same problem, to pause my game when user removes headset for his /her head.
After trying alot of thing i finnaly got it working like i wanted by adding my code to a certain place in update function in the OVR Manager script