Hi, I’ve built a game with a timer, and there are sounds that play at specific points in time. Using the code below, only my ending sounds work (stopping the music & playing final game over sound) but none of the sounds along the way are played. Can anyone say what I’m doing wrong?
Thanks for any advice!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class UICount : MonoBehaviour
{
[SerializeField] float startTime;
[SerializeField] TMP_Text timerText;
float currentTime;
bool timerStarted = false;
public AudioSource EndGameAudio;
public AudioSource HelpMe;
public AudioSource Mommy;
public AudioSource Music;
public AudioSource Hurry;
public bool playing;
private float Timer;
// Start is called before the first frame update
void Start()
{
currentTime = startTime;
timerStarted = true;
}
// Update is called once per frame
void Update()
{
if (timerStarted)
{
currentTime -= Time.deltaTime;
if (currentTime == 150f)
{
HelpMe.Play();
}
if (currentTime == 115f)
{
Mommy.Play();
}
if (currentTime == 15)
{
Hurry.Play();
}
if (currentTime <= 0)
{
timerStarted = false;
currentTime = 0;
Music.Stop();
EndGameAudio.Play();
}
timerText.text = currentTime.ToString("F1");
}
}
}