- Home /
Question by
mingoy_justin · Dec 02, 2020 at 12:34 AM ·
audiotimer
How do i add my audio on my timer?,How to add my audio in a timer
im working on my school project and i need help. how do i add an audio on my timer because i try and it didnt work. here's my work. thank you
using UnityEngine; using UnityEngine.UI;
public class Timer : MonoBehaviour { public Slider timerslider; public Text timertext; public float gametime; AudioSource countdown;
private bool stopTimer;
// Start is called before the first frame update
void Start()
{
stopTimer = false;
timerslider.maxValue = gametime;
timerslider.value = gametime;
}
void playAudio()
{
}
// 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;
}
if(time <= 5)
{
countdown = GetComponent<AudioSource>();
countdown.Play();
}
if (stopTimer == false)
{
timertext.text = texttime;
timerslider.value = time;
}
},i got a 3 2 1 audio and i want to add it in my timer but it never works. im working on a little project for my school project. it doesnt play anything. Here's my code
using UnityEngine; using UnityEngine.UI;
public class Timer : MonoBehaviour { public Slider timerslider; public Text timertext; public float gametime; AudioSource countdown;
private bool stopTimer;
// Start is called before the first frame update
void Start()
{
stopTimer = false;
timerslider.maxValue = gametime;
timerslider.value = gametime;
}
void playAudio()
{
}
// 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;
}
if(time <= 5)
{
countdown = GetComponent<AudioSource>();
countdown.Play();
}
if (stopTimer == false)
{
timertext.text = texttime;
timerslider.value = time;
}
}
Comment
Your answer
Follow this Question
Related Questions
Timing pulses from microphone 0 Answers
Accurate timer for music? 1 Answer
Stop audio playing after a timer reset 2 Answers
Audio Issue 1 Answer
How can I make an alarm clock? 3 Answers