Advertisement
Selzier

Load Scene With Gaze

May 4th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. // Use proper capitalization: https://msdn.microsoft.com/en-us/library/x2dbyw72(v=vs.71).aspx
  6. // time should be named "Time":
  7. public class time : MonoBehaviour {
  8.     // The scene name that will be loaded
  9.     public string sceneToChangeTo;
  10.     // How long to gaze before loading
  11.     public float gazeTime = 2f;
  12.     // A timer var to keep track of how long user has looked at button
  13.     private float timer;
  14.     // If the user is currently gazing at button
  15.     private bool gazedAt;
  16.  
  17.     // Use this for initialization
  18.     void Start() {
  19.         // Currently we are not doing anything at start
  20.     }
  21.  
  22.     // Called once per frame
  23.     void Update() {
  24.         // If user has looked at button
  25.         if (gazedAt) {
  26.             // Increase timer by deltatime
  27.             timer += Time.deltaTime;
  28.             // Once timer has reached 2 seconds
  29.             if (timer >= gazeTime) {
  30.                 // Use SceneManager not Application.Load
  31.                 SceneManager.LoadScene(sceneToChangeTo);
  32.                 // You could also load a scene with the function below:
  33.                 //ChangeScene("MySceneName");
  34.                 // Reset Timer
  35.                 timer = 0f;
  36.             }
  37.         }
  38.     }
  39.  
  40.     // Load a scene by calling this function and passing a string
  41.     public void ChangeScene(string scene) {
  42.         // Use SceneManaer to load scene
  43.         SceneManager.LoadScene(scene);
  44.     }
  45.  
  46.     // Pointer Enter event
  47.     public void PointerEnter() {
  48.         //Debug.Log("pointer enter");
  49.         gazedAt = true;
  50.     }
  51.     // Pointer Exit event
  52.     public void PointerExit() {
  53.         //Debug.Log("pointer exit");
  54.         gazedAt = false;
  55.     }
  56.     // Pointer Down event
  57.     public void PointerDown() {
  58.         Debug.Log("pointer down");
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement