How do you add audio to Audio Clip (via scripting) during gameplay?
I'm trying to let the user be able to add audio to an audio source during gameplay with the click of a button (or something like that). How do I do this?
So far I have scripts that allow me to create audio source objects but I'm not sure how to let the user be able to add specific audio clips they want to the audio sources. Is this possible? Any help would be appreciated, please.
Preferably in C# but anything would be helpful.
Answer by JedBeryll · Jun 17, 2016 at 06:01 AM
public AudioSource source;
public void ChangeClip (AudioClip clip) {
source.clip = clip;
}
A clip can be loaded like this: Resources.Load<AudioClip>("path to the clip");
Also there is a static method AudioSource.PlayClipAtPoint(clip, position);
Sorry, this doesn't work for me. Would you elaborate, please?
What exactly does this script do? What should it do?
I'm trying to be make something where the user can change an audio source's audio clip during gameplay mode. Something where they can access a folder of audio clips and insert the audio clip themselves...
Any help/ elaboration you can give would be appreciated.
In itself it doesn't do much but this is how you change the audioclip of a source at runtime. You would still have to call Play() on the source by the way.
If you want to load from a local folder you can use the WWW class to load the audioclips ins$$anonymous$$d of Resources. I think you can only play ogg and wav files this way (not sure).
@JedBeryll Thanks for your advice. I'm currently working through it all trying to get it to work... I'll let you know how it goes.
Your answer
Follow this Question
Related Questions
How to mute multi-able audioclips within a single audiosource? 0 Answers
Detecting when two different audio sources are emitting sound in Unity 0 Answers
Audio doesnt play in the phone but play on the editor 0 Answers
Is there any known way of sharing audio files from unity to other platforms i.e whatsapp 0 Answers