I’ve found some unity3d code online for a lap timer. I added the script to a collider with a trigger. The timer starts immediately when the scene is run, which is good but how do i make it so when you hit the box collider the time goes back to zero(resets) and counts up again? Its C# so i’m a little lost, just getting used to the javascript.
using UnityEngine;
using System.Collections;
public class LapTimer : MonoBehaviour {
private float startTime;
private float ellapsedTime;
void TimerStart()
{
startTime = Time.time;
}
void Update()
{
ellapsedTime = Time.time - startTime;
}
void OnGUI(){
GUI.TextArea(new Rect(10,30,60,20), (ellapsedTime.ToString()));
}
}
with javascript it would have been something like below, but how do you do it in C#?
function OnTriggerEnter (other : Collider) {
//something in here involvng getting the timer to start over again
}
Also the timer show like 10 digits after the decimal.How do I make it only show one decimal place (10.4) instead of(10.44645646)
This would be mathf.round or something in java right? but what about C#, is there a rounding code?