Audio source stops but I don’t know why. There are no other scripts that affect the audio source but it stops playing. Please help.
AudioClips cannot share an AudioSource, unless you use the method PlayOneShot. However, PlayOneShot will not allow use of any advanced options, such as looping. You will need a separate source for any AudioClips you need to do anything clever with.
An AudioSource is a CD-player and an AudioClip is a CD. Can your CD-player play multiple CDs at the same time?
Audio Sources by default play an Audio Clip as a ‘one-shot’; that is, the file plays its entire duration, then will permanently stop, until told to play the same file again.
In the Unity Editor, find your Audio Source, and make sure that the checkbox ‘Loop’ is checked; programmatically, you can attach some script to the same game object that hosts the Audio Source and in method Start()
use the command audio.loop = true;
to tell the audio source to loop.
The editor approach is simpler and more efficient, though. I hope that helps.
Edit > Player Settings > Script Execution.
Under (Default Time) click on the Plus(+) Sign on the bottom right to add the Script(GameManager Script) that should run before any other Script. The script name doesn’t matter, just the concept of which Script you want to run before another. that being said if the script works do not follow these steps at all, your code is fine as is. Only use it if your script is interfering with time order of another Script from performing properly. Which is usually the GameManager and AudioManager I’ve only came across.
This is what helped my music to start playing again because my GameManager Script and AudioManager Script was loading(running) at the same or wrong time which I guess caused it not to recognize the AudioManager.instance I wrote to the GameManager. Hope this helps you as it did me, Cheers!