Timer doesnt stop on collision,How can i stop that timer on a collision
I can't understand why this won't work. I must move the OnTriggerEnter? Please help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class LevelTimer : MonoBehaviour
{
public MeshCollider Vittoria;
TextMeshProUGUI timerText;
bool Attivo;
float j;
bool finito;
void Start()
{
timerText = GetComponentInChildren<TMPro.TextMeshProUGUI>();
Attivo = false;
finito = false;
}
void Update()
{
if (Attivo && !finito)
{
float t = Time.timeSinceLevelLoad - j;
float milliseconds = (Mathf.Floor(t * 100) % 100);
int seconds = (int)(t % 60);
t /= 60; // divide current time y 60 to get minutes
int minutes = (int)(t % 60);
t /= 60; // divide by 60 to get hours
int hours = (int)(t % 24);
timerText.text = string.Format("{0}:{1}:{2}.{3}", hours.ToString("00"), minutes.ToString("00"), seconds.ToString("00"), milliseconds.ToString("00"));
}
if (Input.anyKey)
{
Attivo = true;
float j = Time.timeSinceLevelLoad;
}
}
void OnTriggerEnter(Collider other)
{
finito = true;
}
}
Comment