07-19-2013 09:39 AM
using UnityEngine;
using System.Collections;
public class PauseMenuCode : MonoBehaviour
{
// public GameObject mL;
int Paused = 0;
int notPaused = 1;
int running;
MouseLook mouselook;
// Use this for initialization
void Start ()
{
Screen.lockCursor = true;
Screen.showCursor = true;
Time.timeScale = Paused;
mouselook = GetComponent<MouseLook>();
}
void OnGUI() {
if (Time.timeScale == Paused && running != 1) {
if (GUI.Button(new Rect(Screen.width/2,Screen.height/2,100,50),"Start Game")) {
Time.timeScale = notPaused;
running = 1;
mouselook.gameRunning = 1;
}
}
else if (Time.timeScale == Paused && running == 1) {
if (GUI.Button(new Rect(Screen.width/2,Screen.height/2,100,50),"Resume Game")) {
Time.timeScale = notPaused;
mouselook.gameRunning = 1;
}
}
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape) && Time.timeScale == notPaused && running != 0) {
Screen.lockCursor = false;
Screen.showCursor = true;
Time.timeScale = Paused;
mouselook.gameRunning = 0;
}
else if ( Input.GetKeyDown(KeyCode.Escape) && Time.timeScale == Paused && running != 0) {
Screen.lockCursor = true;
Screen.showCursor = false;
Time.timeScale = notPaused;
mouselook.gameRunning = 1;
}
if (Time.timeScale != Paused) {
Screen.lockCursor = true;
}
}
}
public float gameRunning = 0F;
void Update () {
if (gameRunning != 0) {
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
}
if (gameRunning == notPaused) { ~Do the code where the cameras would change(Get) the orientation of the Oculus Rift~}In the right place.
using UnityEngine;
using System.Runtime.InteropServices;
[RequireComponent(typeof(Camera))]
//-------------------------------------------------------------------------------------
// ***** OVRCamera
//
// OVRCamera is used to render into a Unity Camera class.
// This component handles reading the Rift tracker and positioning the camera position
// and rotation. It also is responsible for properly rendering the final output, which
// also the final lens correction pass.
//
public class OVRCamera : OVRComponent
{
#region Member Variables
// PRIVATE MEMBERS
// If CameraTextureScale is not 1.0f, we will render to this texture
private RenderTexture CameraTexture = null;
// Default material, just blit texture over to final buffer
private Material BlitMaterial = null;
// Color only material, used for drawing quads on-screen
private Material ColorOnlyMaterial = null;
private Color QuadColor = Color.red;
// Scaled size of final render buffer
// A value of 1 will not create a render buffer but will render directly to final
// backbuffer
private float CameraTextureScale = 1.0f;
// We will search for camera controller and set it here for access to its members
private OVRCameraController CameraController = null;
public float gameRunning = 1F;
void SetCameraOrientation()
{
Quaternion q = Quaternion.identity;
Vector3 dir = Vector3.forward;
//if(gameRunning == 1) {
//Debug.Log (gameRunning);
// Main camera has a depth of 0, so it will be rendered first
if(gameObject.camera.depth == 0.0f)
{
// If desired, update parent transform y rotation here
// This is useful if we want to track the current location of
// of the head.
// TODO: Future support for x and z, and possibly change to a quaternion
if(CameraController.TrackerRotatesY == true)
{
Vector3 a = gameObject.camera.transform.rotation.eulerAngles;
a.x = 0;
a.z = 0;
gameObject.transform.parent.transform.eulerAngles = a;
}
// Read shared data from CameraController
if(CameraController != null)
{
// Read sensor here (prediction on or off)
if(CameraController.PredictionOn == false)
OVRDevice.GetOrientation(0, ref CameraOrientation);
else
OVRDevice.GetPredictedOrientation(0, ref CameraOrientation);
}
// This needs to go as close to reading Rift orientation inputs
OVRDevice.ProcessLatencyInputs();
}
// Calculate the rotation Y offset that is getting updated externally
// (i.e. like a controller rotation)
float yRotation = 0.0f;
CameraController.GetYRotation(ref yRotation);
q = Quaternion.Euler(0.0f, yRotation, 0.0f);
dir = q * Vector3.forward;
q.SetLookRotation(dir, Vector3.up);
// Multiply the camera controllers offset orientation (allow follow of orientation offset)
Quaternion orientationOffset = Quaternion.identity;
CameraController.GetOrientationOffset(ref orientationOffset);
q = orientationOffset * q;
// Multiply in the current HeadQuat (q is now the latest best rotation)
if(CameraController != null)
q = q * CameraOrientation;
// * * *
// Update camera rotation
//Here I add the code for if the game is running, find the orientation and set it
if(gameRunning != 0) {
gameObject.camera.transform.rotation = q;
}
// * * *
// Update camera position (first add Offset to parent transform)
gameObject.camera.transform.position =
gameObject.camera.transform.parent.transform.position + NeckPosition;
// Adjust neck by taking eye position and transforming through q
gameObject.camera.transform.position += q * EyePosition;
}
if(gameRunning != 0) {
gameObject.camera.transform.rotation = q;
}
using UnityEngine;
using System.Collections;
public class PauseMenuCode : MonoBehaviour {
private int running = 1;
OVRCamera camera;
public void Start(){
running = 1;
Time.timeScale = 1;
AudioListener.volume = 1;
Screen.showCursor = false;
Screen.lockCursor = true;
camera = GetComponentInChildren<OVRCamera>();
}
public void Update(){
if(Input.GetKeyDown("escape")){
//check if game is already paused, then unpause it
if(running == 0){
running = 1;
Time.timeScale = 1;
Screen.showCursor = false;
camera.gameRunning = 1;
}
//check if game isn't paused, then pause it
else if(running == 1){
running = 0;
Time.timeScale = 0;
Screen.showCursor = true;
camera.gameRunning = 0;
}
}
}
public void OnGUI(){
if(running != 1){
//Make a background box
GUI.Box(new Rect(Screen.width /2 - 100,Screen.height /2 - 100,250,200), "Pause Menu");
//Quit
if (GUI.Button(new Rect(Screen.width /2 - 100,Screen.height /2 + 50,250,50), "Quit Game")){
Application.Quit();
}
}
}
}
07-22-2013 08:31 AM
// this C# code script must replace the orginal Right OVRCamera script
using UnityEngine;
using System.Collections;
public class ROVRCamera : OVRCamera
{
}
// this C# code script must replace the orginal Left OVRCamera script
using UnityEngine;
using System.Collections;
public class LOVRCamera : OVRCamera
{
}
using UnityEngine;
using System.Collections;
public class PauseMenuCode : MonoBehaviour
{
private int running = 1;
/// EDITED: Remove orginale single reference
//OVRCamera camera;
//// EDITED: Replace it with 2 seperate ones
LOVRCamera cameraL;
ROVRCamera cameraR;
public void Start()
{
running = 1;
Time.timeScale = 1;
AudioListener.volume = 1;
Screen.showCursor = false;
Screen.lockCursor = true;
//// EDITED: Remove orginale single reference
// camera = GetComponentInChildren<OVRCamera>();
//// EDITED: Replace it with 2 seperate ones
cameraL = GetComponentInChildren<LOVRCamera>();
cameraR = GetComponentInChildren<ROVRCamera>();
}
public void Update()
{
if(Input.GetKeyDown("escape"))
{
//check if game is already paused, then unpause it
if(running == 0)
{
running = 1;
Time.timeScale = 1;
Screen.showCursor = false;
//// EDITED: Remove orginale single reference
// camera.gameRunning = 1;
//// EDITED: Replace it with 2 seperate ones
cameraL.gameRunning = 1;
cameraR.gameRunning = 1;
}
//check if game isn't paused, then pause it
else if(running == 1)
{
running = 0;
Time.timeScale = 0;
Screen.showCursor = true;
//// EDITED: Remove orginale single reference
// camera.gameRunning = 0;
//// EDITED: Replace it with 2 seperate ones
cameraL.gameRunning = 0;
cameraR.gameRunning = 0;
}
}
}
public void OnGUI()
{
if(running != 1)
{
//Make a background box
GUI.Box(new Rect(Screen.width /2 - 100,Screen.height /2 - 100,250,200), "Pause Menu");
//Quit
if (GUI.Button(new Rect(Screen.width /2 - 100,Screen.height /2 + 50,250,50), "Quit Game"))
{
Application.Quit();
}
}
}
}
Did this answer your question? If it didn’t, use our search to find other topics or create your own and other members of the community will help out.
If you need an agent to help with your Meta device, please contact our store support team here.
Having trouble with a Facebook or Instagram account? The best place to go for help with those accounts is the Facebook Help Center or the Instagram Help Center. This community can't help with those accounts.
Check out some popular posts here:
Getting Help from the Meta Quest Community
Tips and Tricks: Charging your Meta Quest Headset