I’m new to unity and would like to develop a simple VR game that a timer starts when the player looks at the Start button and the timer stops when the player looks at the stop button. The timer function works, but I am having trouble integrating it with the gazedAt function. At the moment, the timer starts automatically without looking at it. Any help would be great!!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timer : MonoBehaviour {
public Text timerLabel;
public bool pauseTimer = true;
private float time;
void Start() {
SetGazedAt(false);
}
void Update() {
if(pauseTimer)
time += Time.deltaTime;
var minutes = Mathf.Floor(time / 60);
var seconds = time % 60;//Use the euclidean division for the seconds.
var fraction = (time * 100) % 100;
//update the label value
timerLabel.text = string.Format ("{0:00} : {1:00} : {2:00}", minutes, seconds, fraction);
}
//Start Timer
public void SetGazedAt(bool gazedAt){
//Start Timer Here
pauseTimer = true;
Debug.Log("Timer Started");
}
}