Stopwatch.cs
using UnityEngine;
using TMPro;
public class Stopwatch : MonoBehaviour
{
public bool hasFinished;
float minutes;
float seconds;
public TextMeshProUGUI stopwatch;
void Update()
{
if (hasFinished == false)
{
seconds += Time.deltaTime;
if (seconds >= 60)
{
minutes += 1;
seconds -= 60;
}
}
int m = Mathf.RoundToInt(minutes);
int s = Mathf.RoundToInt(seconds);
stopwatch.text = m + ":" + s;
}
}
Finish.cs
using UnityEngine;
public class Finish : MonoBehaviour
{
public Stopwatch time;
public RoutePoint finishPoint;
private void OnTriggerEnter(Collider other)
{
if (finishPoint.isActiveForPlayer)
{
if (other.tag == "Player")
{
time.hasFinished = true;
}
}
}
}
RoutePoint.cs
using UnityEngine;
public class RoutePoint : MonoBehaviour
{
public RoutePoint nextPoint;
public GameObject model;
public bool isActiveForPlayer;
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
if (isActiveForPlayer)
{
isActiveForPlayer = false;
model.SetActive(false);
if (nextPoint != null)
{
nextPoint.isActiveForPlayer = true;
nextPoint.model.SetActive(true);
}
}
}
}
}