i have a simple trigger, Cube/box collider, named Startpoint.
when my player object crosses it, i want a timer to start counting up.
like, before the trigger, the GUI should be displaying [0:00:00] (min, secs, millisecs).
and OnTrigger, start the timer, 1,2,3,4,5,… seconds.
i also have 2nd trigger cube/box collider, named Endpoint.
when the player object crosses/triggers it, the timer stops, and that will be the player's ellapsed time.
here's what i've tried writing, referencing from other questions/answers and researching on my own, but it's not working =\
attached this c# script to my Startpoint game object:
using UnityEngine;
using System.Collections;
public class StartingLine : MonoBehaviour {
private float startTime;
private string ellapsedTime;
void Awake(){
startTime = Time.time;
}
// Update is called once per frame
void Update () {
}
//void OnTriggerEnter(){
// GUI.Label(new Rect(10, 10, 100, 20), (startTime));
// float startTime = Time.time;
//
// guiText.text = ""+startTime;
//}
void OnGUI(){
ellapsedTime = Time.time - startTime;
GUI.Label(new Rect(10, 10, 100, 20), ellapsedTime);
}
}
this script currently gives me the error mentioned above at the top of my question. can someone show me the right way of writing my timer? as well as the End time part.. and would i be able to create a gui skin, for a custom HUD that displays this timer?