How do I loop music in C#
I understand that questions like this have been asked before, but I haven't been successful in using any solutions for what I currently have. I have this code set up so that when a menu opens within a game a randomly selected piece of music will play from a range. The music plays fine, but I can't work out how to make it loop when it ends.
This is the main part of code I have for how I've tried to make it loop:
void music()
{
source = GetComponent<AudioSource>();
source.loop = true;
source.PlayOneShot(menu);
}
Answer by JScotty · Nov 15, 2016 at 10:57 AM
use source.Play(menu) instead of PlayOneShot, because PlayOneShot does what the method says. I will play one shot.
https://docs.unity3d.com/ScriptReference/AudioSource.Play.html
Your answer
Follow this Question
Related Questions
Break the loop when there are no more questions 0 Answers
Unity update does not be called when lock screen 0 Answers
if ALL items in array are something 1 Answer
C# Use Multiple instances of Script or For Loop Once 1 Answer
Nested For loop Grouping 0 Answers