- Home /
Music Choppy and Weird
I have a script in C# that plays different peices of music at each hour and when I start it up it sounds really weird. I think its because every frame its checking for time and messing up the audio playing. i have seen other posts covering things along the lines of this problem. I have some code but I'm not sure what to do next. Any help would be appreciated.
using UnityEngine; using System.Collections; using System;
public class TimeMusic : MonoBehaviour {
public AudioClip song;
// Update is called once per frame
void Update () {
int sysHour = System.DateTime.Now.Hour;
if (sysHour == 17)
audio.PlayOneShot(song);
}
}
add the condition : if(! audio.isPlaying)
before trying to play any sound in an update.
As it is you keep playing the sound from the beginning every frame.
Your answer
Follow this Question
Related Questions
Audio controls disabled??! 0 Answers
Stereo Mix as Input? 1 Answer
Can not play a disabled audio source 2 Answers
Stop audio/background music from pausing when showing ads 1 Answer
Loading music for initial scene loading takes a very long time 1 Answer