Then ChatGPT didn’t help you with the code. ChatGPT will output things with an air of confidence even if those things will not even remotely function and should not be used until this is resolved or you are experienced enough a developer to recognize these issues. What does “the game cannot start” mean? Are there errors? What’s happening?
Also, use code tags.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Timer : MonoBehaviour
{
[SerializeField] TextMeshProUGUI timerText;
[SerializeField] float initialTime;
float remainingTime;
bool timerStarted = false;
// Update is called once per frame
void Update()
{
if (timerStarted)
{
remainingTime -= Time.deltaTime;
if (remainingTime <= 0)
{
remainingTime = 0;
timerText.color = Color.red;
}
}
int minutes = Mathf.FloorToInt(Mathf.Abs(remainingTime) / 60);
int seconds = Mathf.FloorToInt(Mathf.Abs(remainingTime) % 60);
timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
public void StartTimer()
{
remainingTime = initialTime;
timerStarted = true;
}
}
Where are you calling StartTimer()? The code that ChatGPT generated literally can not function if you aren’t calling that because your default timer state is false.