Dakeyras
Dakeyras

Reputation: 2251

How do I loop through a song several times?

I want to play a specific song while a level is playing, but so far I've only used audio.PlayOneShot(soundClip). How can I play a song multiple times until the level changes?

Upvotes: 0

Views: 2974

Answers (2)

CC Inc
CC Inc

Reputation: 5918

As Bart pointed out, you can change the audio source's loop property from the Inspector, but you can also do it from code.

// ON SCENE LOAD
audio.loop = true;
audio.PlayOneShot(soundClip);

// ON SCENE CHANGE
audio.loop = false;
audio.Stop();
Application.LoadLevel(0); // or whatever

When you first load a level, you play the clip and loop it, and when you change the level you stop the clip and disable it looping (actually not necessary).

Upvotes: 1

Bart
Bart

Reputation: 20028

You will have to make sure that the audio source's loop is set to true. This is a checkbox for your audio source that you will need to enable.

enter image description here

If you then simply play it, it should loop.

Upvotes: 1

Related Questions