- Home /
How to play a sound from the middle of the sound?
I have high quality car engine sounds that I need to play from various point in the sound, say I accelerate to 25% then when I release the accelerator, the decceleration sound should start at 25% to match the acceleration sound, is this possible? Play a sound with an offset(in samples or time)?
If not possible is there more useful sound libraries I can use for Unity that would work on iphone and android?
Thank you
Answer by Evil-Dog · May 06, 2011 at 02:26 PM
Sorry to answer my own question but the answer is indeed obvious after all. Setting the timeSamples property before calling Play() does the trick. I assumed timeSamples was read-only.
Don't be sorry, it's a good thing. Now if some one else has the same problem they can look it up here :)
@Evil-Dog - Could you please post a sample script.
Thank you, Ben
Thanks, Do you have any idea of playing movie texture from middle ins$$anonymous$$d of from starting?
You can use .time instead of .timeSamples, to "set the playback position in seconds" instead of using sample count
Answer by flaviusxvii · May 05, 2011 at 08:42 PM
You could set the volume to 0 and then set it to 100% after the right amount of time has passed.
But why not just slice up the audio into it's component pieces and play them individually like any sane person would do? This sounds like a seriously problematic work around.
$$anonymous$$aybe I didn't explain myself correctly, I have a sound that's from idle to max speed, a long acceleration sound. And a deccel sound from max speed to idle. So if I accel to 25%, and release the pedal, the deccel sound must start at 75%, so it matches with the accel sound. Anyway I think I can set timeSamples to the right spot and play the sound. I thought it was read-only but I've seen an answer along those lines somewhere. To understand, check my game Road of the Dead which I'm porting to Unity now.
http://www.newgrounds.com/portal/view/550714