- Home /
Looping an AudioClip var...
I have a declared variable(soundvar), an AudioClip, that I need to loop. It is not attached to a audio source. Can I make a variable loop independent of an audio source?
I was thinking along the syntax of soundvar.loop = true?
My javascript is not very strong, thank you for humoring my inquiry.
This just doesn't make sense. To play an audio, you need an audio source, that's where the sound comes from, yeah?! Source.
To toggle looping on an audioSource, use http://docs.unity3d.com/Documentation/ScriptReference/AudioSource-loop.html
There is a source on the object in question, but it has an assigned clip in the inspector; I'm composing a script that will independently trigger audio not assigned to the source, but my question is can I get that audio to loop by not using the source directly?
Your question doesn't make sense. There is no audio without the source so you cannot get the audio to loop without it.
Answer by Tarlius · Feb 24, 2013 at 05:26 PM
You can play sound without attaching it to the source, but you lose control of it, and if I recall correctly, you cannot loop it (without writing extra logic to tell it to play again, which will run into a whole new set of problems)
The command for playing once is PlayOneShot.
What you could do, is have a prefab of an AudioSource and instantiate and attach the clip to it in code.
This is correct, Upvoted. PlayOneShot and PlayClipAtPoint does not loop, therefore as suggested create a prefab with an audioSource, audioClip in the inspector and set to loop.
Your answer
Follow this Question
Related Questions
What could make the audio loop? 2 Answers
JavaScript Play Audiosource Problem 1 Answer
Audio source play stop in Unity5 3 Answers
Why does the audio sound different than the original ? 0 Answers