I am trying to make a game where you have 3 seconds to shoot a moving alien that keeps respawning. I want it to be that when I shoot it it sets the time back to 3 seconds so I have 3 seconds to try and shoot it again and e.t.c until I dont manage to shoot it in 3 seconds and I lose. I have everything in place except the timer script that I want to countdown showing seconds and milliseconds. Could you please try to make this script countdown from a number instead of up from 0?
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Timer : MonoBehaviour
{
public TextMeshProUGUI timerText;
public bool playing;
public float timer;
void Update()
{
if (playing == true)
{
timer += Time.deltaTime;
UpdateText(timer, timerText);
}
}
void UpdateText(float t, TextMeshProUGUI text)
{
int seconds =- Mathf.FloorToInt(t % 60f);
int milliseconds =- Mathf.FloorToInt((t * 100f) % 100f);
text.text = seconds.ToString("00") + "." + milliseconds.ToString("0");
}
}