Hi, I would like to know how can I make the background music fade out after timer is 00:00 ?
How can I add that to this script ?
This is my timer script.
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
using System.Collections;
public class TimerManagerScript : MonoBehaviour
{
public float timeLeft;
public bool timerOn = false;
public GameObject player;
private bool stopMovement;
public TMP_Text timerTxt;
void Start()
{
stopMovement = GameObject.Find("Player").GetComponent<PlayerMovement>().enabled;
timerOn = true;
}
void Update()
{
timerCheck();
}
public void timerCheck()
{
if (timerOn)
{
if (timeLeft > 0)
{
timeLeft -= Time.deltaTime;
updateTimer(timeLeft);
}
else
{
timeLeft = 0;
timerOn = false;
timerTxt.color = Color.red;
Destroy(player);
stopMovement = false;
StartCoroutine(ResetLevel());
}
}
}
public void updateTimer(float currentTime)
{
currentTime += 1;
float minutes = Mathf.FloorToInt(currentTime / 60);
float seconds = Mathf.FloorToInt(currentTime % 60);
timerTxt.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
IEnumerator ResetLevel()
{
yield return new WaitForSeconds(2);
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}