Start Finish Timer
I'm want to make an object that can start a timer and an object that can end it. I have written a script that can do that except it starts immediately. I tried putting two in ontriggerenter twice one for the start line and one for the finish line. but it gave me an error saying that there is a another one with the same parameters. I want to know how to make it work.
here is the script that starts the timer instantly. the tag for the start line is Start the tag for the finish line is End
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timer : MonoBehaviour {
public Text timerText;
private float startTime;
private bool finished = false;
void Start ()
{
startTime = Time.time;
}
void Update () {
if (finished)
return;
float t = Time.time - startTime;
string munites = ((int)t / 60).ToString ();
string seconds = (t % 60).ToString ("f2");
timerText.text = munites + ":" + seconds;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("End"))
finished = true;
}
}
Your answer
Follow this Question
Related Questions
Issues trying to activate an image through OnTriggerEnter/Exit/Stay(Flickering) 1 Answer
Setting OnTriggerEnter to a second object collider 2 Answers
Score counted multiple times when several projectiles impact the same target 1 Answer
Crane Pick up script - setting new parent 0 Answers
On trigger enter help 1 Answer