AudioSource repeatedly called
I wrote the following script to play an audio source when the timer reaches 0, it keeps calling the audio source and it echoes. Is the error that it's under the update function? It doesn't get recognised when I move it under the start function, or my timer stops working. Any ideas.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class LoLCountDownTimer : MonoBehaviour {
float currentTime = 0f;
float startingTime = 30f;
public AudioSource Shutdown;
[SerializeField] Text countdownText;
// Use this for initialization
void Start()
{
currentTime = startingTime;
}
// Update is called once per frame
void Update()
{
currentTime -= 1 * Time.deltaTime;
countdownText.text = currentTime.ToString("00");
if (currentTime <= 0)
{
currentTime = 0;
if (currentTime <= 0)
//Shutdown = GetComponent<AudioSource>();
Shutdown.PlayOneShot(Shutdown.clip);
{
}
}
}
}
Your answer
Follow this Question
Related Questions
How to create buttons that toggle the audio clip playing for a game object? 0 Answers
What causes weird cracking/popping sound when playing 3d sound 1 Answer
Getting nullReferenceException when respawning a gameObject and trying to access the audio source. 0 Answers
Can't get an AudioSource to play on awake 2 Answers
Error FMOD::Sound instance - no sound is being played from AssetBundle 0 Answers