I’ve got an audio file attached to an object that plays when that object collides above a certain relative velocity threshhold. What I would like to do is to change it so that above a certain relative velocity one sound plays and below that relative velocity another sound plays.
My questions are: Can I apply more than one audio file to an object? If so, how do I call each audio file separately?
Is something like this possible [PSEUDOCODE]?
function OnCollisionEnter (col : Collision) {
if (col.relativeVelocity.magnitude > 1.0) {
audio.one.Play ();
}
else {
audio.two.Play ();
}
}
That’s an interesting solution. Last time I asked that question (about multiple audio souces and a singe object), I was told I couldn’t do it and that I had to create a dummy object and attach the audio to that. Eventhough I don’t really understand the code, I get the concept.
Would you make that snippet available on the WIKI?
The one possible caveat (that I don’t recall for sure) is that a sound already playing this way might be interrupted if the audio clip is changed out from underneath it. I believe it will be interrupted, just don’t have a quick way to verify…
If so, there are certainly ways around it. For example you could instantiate a temporary game object at the location that plays the sound at the proper location, and then destroys itself. The object could even be attached to the original object if you need the sound to keep moving around.