Selzier

ButtonRotateMaze

Feb 21st, 2016
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using VRStandardAssets.Utils;
  4.  
  5. namespace VRStandardAssets.Maze {
  6.     public class ButtonRotateMaze : MonoBehaviour {
  7.  
  8.         [SerializeField]private VRInteractiveItem m_InteractiveItem;       // Reference to the VRInteractiveItem
  9.         [SerializeField]private VRInput m_VRInput;                         // Reference to the VRInput to detect button presses.
  10.  
  11.         public Transform VRHead;
  12.         public CameraOrbit cameraOrbitScript;                               // CameraOrbit script
  13.         public float rotationAmount = 200f;                                 // How much to rotate the maze when a button is clicked
  14.         private bool m_GazeOver;                                            // Whether the user is currently looking at the bar.
  15.  
  16.         private void OnEnable() {
  17.             m_VRInput.OnDown += HandleDown;
  18.             m_VRInput.OnUp += HandleUp;
  19.  
  20.             m_InteractiveItem.OnOver += HandleOver;
  21.             m_InteractiveItem.OnOut += HandleOut;
  22.         }
  23.  
  24.         private void OnDisable() {
  25.             m_VRInput.OnDown -= HandleDown;
  26.             m_VRInput.OnUp -= HandleUp;
  27.  
  28.             m_InteractiveItem.OnOver -= HandleOver;
  29.             m_InteractiveItem.OnOut -= HandleOut;
  30.         }
  31.         private void HandleDown() {
  32.             // If the user is looking at the bar start the FillBar coroutine and store a reference to it.
  33.             if (m_GazeOver) {
  34.                 if (VRHead.localRotation.eulerAngles.y < 150f) {
  35.                     RotateMaze(rotationAmount);
  36.                 }else {
  37.                     RotateMaze(-rotationAmount);
  38.                 }
  39.                
  40.             }
  41.  
  42.         }
  43.  
  44.         // Not using now
  45.         private void HandleUp() {
  46.         }
  47.  
  48.         private void HandleOver() {
  49.             // The user is now looking at the bar.
  50.             m_GazeOver = true;
  51.         }
  52.  
  53.  
  54.         private void HandleOut() {
  55.             // The user is no longer looking at the bar.
  56.             m_GazeOver = false;
  57.         }
  58.  
  59.         // Use this for initialization
  60.         void Start() {
  61.  
  62.         }
  63.  
  64.         // Update is called once per frame
  65.         void Update() {
  66.  
  67.         }
  68.  
  69.         public void RotateMaze(float amount) {
  70.             StartCoroutine(cameraOrbitScript.RotateCamera(amount));
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment