Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- // Use proper capitalization: https://msdn.microsoft.com/en-us/library/x2dbyw72(v=vs.71).aspx
- // time should be named "Time":
- public class time : MonoBehaviour {
- // The scene name that will be loaded
- public string sceneToChangeTo;
- // How long to gaze before loading
- public float gazeTime = 2f;
- // A timer var to keep track of how long user has looked at button
- private float timer;
- // If the user is currently gazing at button
- private bool gazedAt;
- // Use this for initialization
- void Start() {
- // Currently we are not doing anything at start
- }
- // Called once per frame
- void Update() {
- // If user has looked at button
- if (gazedAt) {
- // Increase timer by deltatime
- timer += Time.deltaTime;
- // Once timer has reached 2 seconds
- if (timer >= gazeTime) {
- // Use SceneManager not Application.Load
- SceneManager.LoadScene(sceneToChangeTo);
- // You could also load a scene with the function below:
- //ChangeScene("MySceneName");
- // Reset Timer
- timer = 0f;
- }
- }
- }
- // Load a scene by calling this function and passing a string
- public void ChangeScene(string scene) {
- // Use SceneManaer to load scene
- SceneManager.LoadScene(scene);
- }
- // Pointer Enter event
- public void PointerEnter() {
- //Debug.Log("pointer enter");
- gazedAt = true;
- }
- // Pointer Exit event
- public void PointerExit() {
- //Debug.Log("pointer exit");
- gazedAt = false;
- }
- // Pointer Down event
- public void PointerDown() {
- Debug.Log("pointer down");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement