Next: , Up: Audio   [Contents][Index]


3.1 Music Manager

Component: MusicManager

This component allows the user to adjust the volume of music, or (if enabled by you) select from one of 3 musical sets. It provides generic music handling functionality. For global in-game music, add this component to an object and add a ’Persistent’ component, to prevent it from being destroyed when the scene changes. Alternatively, add a different one to each scene for varied music from scene-to-scene.

To create a speaker playing music, use this component without the ’Persistent’ component, and set the ’Spatial Blend’ setting on the ’Audio Source’ all the way to ’3D’.

Optional Field of MusicManager: AudioClip startSplashSound

If supplied, play this before the first track

Field of MusicManager: float musicVolume

A modifier applied to music globally

Default value: 0.8f

Field of MusicManager: Slider volumeSlider

A UGUI slider for volume control. Works on all platforms.

Field of MusicManager: bool enableMusic

Should the music play now?

Default value: true

IMGUI Settings

Field of MusicManager: bool showGui

Should we show the legacy Unity GUI? Not suitable for mobile.

Default value: false

Field of MusicManager: Rect audioGUI

Normalized viewport rectangle representing the are the GUI is drawn in, numbers between 0 and 1

Default value: new Rect(0.01f, 0.01f, 0.3f, 0.4f)

Field of MusicManager: MusicCategories musicCategory

What is the default category of music?

Default value: MusicCategories.One

Field of MusicManager: bool allowExtraCategories

Allow the user to select from one of the other categories, or just use one? If false, only the first category is used.

Default value: true

Field of MusicManager: AudioClip[] category1

List of all songs, in order, in the category

Field of MusicManager: AudioClip[] category2

List of all songs, in order, in the category

Field of MusicManager: AudioClip[] category3

List of all songs, in order, in the category

Field of MusicManager: float fadeLevel

If we fade the music, how low should we fade it?

Default value: .06f

Field of MusicManager: float fadeDuration

How long from the start of the fade does it take to transition?

Default value: 3f

Field of MusicManager: bool instantStart

Should we cut to low volume and then fade back? If false, we will fade out smoothly

Default value: true

Available Messages

Message on MusicManager: ToggleMusicGUI ()

Toggles the legacy Unity GUI for music control.

Message on MusicManager: ToggleMusic ()

Turns the music on/off

Message on MusicManager: SetMusicCategory (int)

Allows you to change the music category directly

Argument: The category (1, 2 or 3) of music we wish to select

Message on MusicManager: OpenMenu ()

Enable the legacy GUI

Message on MusicManager: CloseMenu ()

Disable the legacy GUI

Message on MusicManager: ToggleMenu ()

Toggle the legacy GUI

Message on MusicManager: SetMusicVolume ()

Changes the volume just for the MusicManager

Message on MusicManager: FadeOut ()

Fades the current song out smoothly

Message on MusicManager: FadeIn ()

Fades in the current song smoothly

Message on MusicManager: FadeOutOverTime (float)

Fades the music out over a specified amount of time by setting the fade duration

Argument: The amount of time we want the fade to take

Message on MusicManager: FadeInOverTime (float)

Fades the music in over a specified amount of time

Argument: How long we want the fade to take

Message on MusicManager: PlaySong (int)

Plays the song you want from the current category.

Argument: The index of the song you want to play. Indices start at 0 (not 1) so the first song is index 0, second is index 1 etc.

Message on MusicManager: PlaySongLooping (int)

Plays the song you want from the current category, and loops it continuously.

Argument: The index of the song you want to play. Indices start at 0 (not 1) so the first song is index 0, second is index 1 etc.

Optional Field of MusicManager: AudioClip startSplashSound

If supplied, play this before the first track

Field of MusicManager: float musicVolume

A modifier applied to music globally

Default value: 0.8f

Field of MusicManager: Slider volumeSlider

A UGUI slider for volume control. Works on all platforms.

Field of MusicManager: bool enableMusic

Should the music play now?

Default value: true

IMGUI Settings

Field of MusicManager: bool showGui

Should we show the legacy Unity GUI? Not suitable for mobile.

Default value: false

Field of MusicManager: Rect audioGUI

Normalized viewport rectangle representing the are the GUI is drawn in, numbers between 0 and 1

Default value: new Rect(0.01f, 0.01f, 0.3f, 0.4f)

Field of MusicManager: MusicCategories musicCategory

What is the default category of music?

Default value: MusicCategories.One

Field of MusicManager: bool allowExtraCategories

Allow the user to select from one of the other categories, or just use one? If false, only the first category is used.

Default value: true

Field of MusicManager: AudioClip[] category1

List of all songs, in order, in the category

Field of MusicManager: AudioClip[] category2

List of all songs, in order, in the category

Field of MusicManager: AudioClip[] category3

List of all songs, in order, in the category

Field of MusicManager: float fadeLevel

If we fade the music, how low should we fade it?

Default value: .06f

Field of MusicManager: float fadeDuration

How long from the start of the fade does it take to transition?

Default value: 3f

Field of MusicManager: bool instantStart

Should we cut to low volume and then fade back? If false, we will fade out smoothly

Default value: true

Available Messages

Message on MusicManager: ToggleMusicGUI ()

Toggles the legacy Unity GUI for music control.

Message on MusicManager: ToggleMusic ()

Turns the music on/off

Message on MusicManager: SetMusicCategory (int)

Allows you to change the music category directly

Argument: The category (1, 2 or 3) of music we wish to select

Message on MusicManager: OpenMenu ()

Enable the legacy GUI

Message on MusicManager: CloseMenu ()

Disable the legacy GUI

Message on MusicManager: ToggleMenu ()

Toggle the legacy GUI

Message on MusicManager: SetMusicVolume ()

Changes the volume just for the MusicManager

Message on MusicManager: FadeOut ()

Fades the current song out smoothly

Message on MusicManager: FadeIn ()

Fades in the current song smoothly

Message on MusicManager: FadeOutOverTime (float)

Fades the music out over a specified amount of time by setting the fade duration

Argument: The amount of time we want the fade to take

Message on MusicManager: FadeInOverTime (float)

Fades the music in over a specified amount of time

Argument: How long we want the fade to take

Message on MusicManager: PlaySong (int)

Plays the song you want from the current category.

Argument: The index of the song you want to play. Indices start at 0 (not 1) so the first song is index 0, second is index 1 etc.

Message on MusicManager: PlaySongLooping (int)

Plays the song you want from the current category, and loops it continuously.

Argument: The index of the song you want to play. Indices start at 0 (not 1) so the first song is index 0, second is index 1 etc.


Next: , Up: Audio   [Contents][Index]