I am trying to make it so that when a person completes a level, they can calculate how long they took to complete the level. I get this error: The name ‘time’ does not exist in the current context. I have a GUIText called time. I still get this error though. I have changed it in the script. Here is my script:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour
{
public float timerAccuracy = 0.1f; //How frequently will the timer update? Time in seconds.
public bool timerActive = true; //Set this to false when you want to stop the timer
public string textBeforeSeconds = "Time: "; //If you don't want the text before the timer, leave it blank.
public string textAfterSeconds = " seconds"; //If you don't want the text after the timer, leave it blank.
private float currentTime; //The actual time since timerAcive was true
IEnumerator Start ()
{
currentTime = 0; //Time is set to 0 at the start
//Set the appropriate text to the GUI Text
guiText.text = time;
while (true)
{ //Will loop, and preform much like Update()
if (timerActive)
{
//Add (timerAccuracy) to the actual time, every (timerAccuracy) seconds
yield return new WaitForSeconds(timerAccuracy);
currentTime += timerAccuracy;
guiText.text = time;
}
yield return null;
}
}
}