|
Post by tekustudios on Jun 2, 2015 17:40:43 GMT
Hi there!
We've been working in our current game for some years now and we're currently dealing with everyhing that has to do with audio. We have 2 audio engineeres who are taking care of almost everything, but there are some specific situations in which we need to control sounds via code, and I'm a little lost there. I've tried searching for a while but I'm not finding anything, so please excuse me for my extremely basic questions.
First off, I would like to know if there is some callback or something that is launched whenever an audio clip has finished playing (just like any animation would). It would save me a lot of time and code if something like that exists.
Also, our audio guys mostly work with Audio Groups, but I'm still not quite sure how to deal with them. I know how to play and tweak a SoundGroupVariation component, but I can't find how to work with Audio Groups. As an example, the audio guys have created 5 different sounds for pulling switches, and they want them to be played randomly. They have created 5 objects that contain an AudioSource and the SoundGroupVariation component, and all 5 are controlled by a master parent with an Audio Group component with its Variation Sequence set to 'randomized'. They tell me I'm supposed to play it so the sounds work at random, but I don't know ho to do it with code.
Any help will be very much appreciated. Thanks for your time.
|
|
|
Post by DarkTonic Dev on Jun 2, 2015 18:35:37 GMT
There is a callback for SoundFinished. Look in the code section of the readme for it.
To play a random Variation in a Sound Group, use one of the many methods that start with "PlaySound" like: MasterAudio.PlaySound3DAndForget Do not specify the Variation name and it will select one at random. Note that there are no optional parameters in UnityScript so pass a null if you use that.
If the Sound Group has been set up to play Variations top to bottom, then this will instead play them in that order.
All of this is in the readme "triggering audio: code methods" section that you should check out for more info. There's also the API website with far more.
|
|
|
Post by tekustudios on Jun 2, 2015 18:41:12 GMT
Ok, thanks and sorry for wasting your time with this. I did look in the ReadMe but didn't find anything, my bad.
I'll try and let you know if I experience any issues.
|
|
|
Post by DarkTonic Dev on Jun 2, 2015 18:42:31 GMT
No problem.
|
|
|
Post by tekustudios on Jun 8, 2015 8:58:58 GMT
Ok, sorry to come back to this. I'm going nuts with the SoundFinished callback setup. It should be obvious how to use it, but it's driving me nuts. Is there a place where I can check the docs written in C#? The ReadMe I got is in UnityScript and I can't make my C# code work. I'm sure It's stupidly simple, but I'm not sure how to write it.
Thanks.
|
|
|
Post by tekustudios on Jun 8, 2015 9:03:07 GMT
Never mind, I already solved it. It was really simple
|
|
|
Post by tekustudios on Jun 8, 2015 9:25:18 GMT
Oh, and something I couldn't find anywhere: Is there a way I can check whether a sound is playing or not?
|
|
|
Post by DarkTonic Dev on Jun 8, 2015 15:57:50 GMT
None of the readme is UnityScript. I don't use that language. It's all C#.
If you want to check if a sound is still playing after you told it to play, code is like this:
var sfx = MasterAudio.PlaySound3DAtTransform("Arrow");
And then later in the same script:
if (sfx.ActingVariation != null && sfx.ActingVariation.IsPlaying) // it's still playing. }
|
|
|
Post by tekustudios on Jun 8, 2015 16:09:56 GMT
I thought it was unityScript, my bad. Thanks for that
|
|
|
Post by DarkTonic Dev on Jun 8, 2015 18:42:22 GMT
No problem.
|
|