The timerscript is :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
using UnityEngine.SceneManagement;
public class Timer : MonoBehaviour
{
// Start is called before the first frame update
public Slider timerSlider;
public TMP_Text timerText;
public float gameTime;
public int startTimer;
private bool stopTimer;
void Start()
{
stopTimer = false;
timerSlider.maxValue = gameTime;
timerSlider.value = gameTime;
}
// Update is called once per frame
void Update()
{
float time = gameTime - Time.time;
int minutes = Mathf.FloorToInt(time / 60);
int seconds = Mathf.FloorToInt(time - minutes * 60f);
string textTime = string.Format("{0:0}:{1:00}", minutes, seconds);
if ( time <= 0)
{
stopTimer = true;
SceneManager.LoadScene ("Menu");
}
if ( stopTimer == false)
{
timerText.text = textTime;
timerSlider.value = time;
}
}
}
The main menu script is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
public void QuitButton()
{
Application.Quit();
Debug.Log("Quit");
}
public void StartButton()
{
SceneManager.LoadScene("Level 1");
}
}