- Home /
Unmuted sounds playing off-beat
This is going to take some explanation, so please bear with me.
I'm creating a game wherein the player triggers timed sound loops by running into objects. For example, if a player runs into the corresponding object, it creates a sound on beat 1, while running into the object that comes directly after it will create a sound on beat 2, and so on.
To do this, I've created all the sounds in Reason first, and exported each note within a single-bar loop individually. So for the beat 1 sound, I deleted all of the notes in the one bar EXCEPT for beat 1, then exported that bar as an audio file - so the audio file is just the hit on beat 1, then silence for the remainder of the bar. I then do this for every note in the bar, and attach each individual beat to an individual object. The sounds are set to play on awake, and loop, but they're muted. I then use this piece of code to unmute the sound when the player runs into the object:
function OnTriggerEnter (col: Collider) {
if (col.gameObject.name == "SnakeHead1")
audio.mute = false;
renderer.enabled = false;}
The problem I'm having currently is that when I actually play the game, the sounds are not playing on their specified beats. I've checked the individual audio files, and it seems that everything should be in order, so the problem must be coming from something within Unity.
Any help here would be greatly appreciated. Thanks!
What file format are your audio loops in?
Edit : you want to use .wav as mp3s have a silent portion and therefore not loopable (assumed for ID tag and other info)
I am not building for Android, no. Not specifically, at least.
The audio loops are in .wav format. Would that be a problem?
I've also noticed that if I make the sounds unmuted from the start, they are not playing on-time. I can see from the waveforms of the audio that they are definitely set up how I bounced them out originally, though.
I would suggest a test where you don't use PlayOnAwake, but store all the AudioSources in an array one one script. At Start, loop through each AudioSource in the array and tell it to play. Hopefully this will get all the AudioSources to start playing at the same instant.
eg :
var audioLoops : AudioSource[];
function Start()
{
for ( var audioLoop : AudioSource in audioLoops )
{
audioLoop.Play();
}
}
You could also test if mute is the problem, by changing mute to volume = 0;
Your answer
Follow this Question
Related Questions
Background music 0 Answers
How do i add/import sound effects and/or music into my game? 5 Answers
TimeScale with AudioSource 1 Answer
Theme music for approach to object question 1 Answer
How to mute music independent from other sounds using mixers? 0 Answers