🟧
Sounds Good Documentation
English
English
  • Welcome!
  • FIRSTS STEPS
    • Create your first sound
  • Create and use audio outputs
  • Included Prefabs
  • Update from 1.0 to 2.0
  • DOCUMENTATION
    • Assemblies and Namespaces
    • Prefixes
    • Audio objects
      • Sound
        • Properties
        • Methods
      • Music
        • Properties
        • Methods
      • Playlist
        • Properties
        • Methods
      • DynamicMusic
        • Properties
        • Methods
    • Editor windows
      • Audio Creator
      • Audio Collection
      • Output Manager
    • SoundsGoodManager
  • Extras
    • Credits
    • Acknowledgments
Powered by GitBook
On this page
  • πŸ›  How to create a Music object
  • πŸ“ Advanced Example
  1. DOCUMENTATION
  2. Audio objects

Music

A Music object is an instance you can create from code to play one of the music tracks previously created in the Audio Creator window under the Music tab. It represents a complete music trackβ€”such as background themes, main themes, or any audio requiring continuous or atmospheric playback.


πŸ›  How to create a Music object

To use music from code, you must first create the track in the Audio Creator, and then invoke it using its tag or its Track identifier. For example:

new Music("MainTheme").Play();  

Or if you're using a Track directly:

new Music(Track.MainTheme).Play();

If you rename a music track in the Audio Collection window, its code reference (Track.MainTheme) will break.

Music mainTheme = new Music("MainTheme").SetVolume(0.6f)
.SetLoop(true).SetSpatialSound(false);  
mainTheme.Play();  

πŸ“ Advanced Example

Music dungeonTheme = new Music(Track.Dungeon)  
    .SetVolume(0.4f)  
    .SetLoop(true)            // Loops the track when it ends
    .SetFadeOut(2.5f)         // 2.5-second fade-out at the end
    .SetOutput(Output.Music)  // Assigns it to a specific output channel
    .OnPause(() => Debug.Log("Dungeon theme paused"))  
    .Play();  

πŸ‘‰ Configuration of a dungeon theme with low volume, 2.5-second fade-out, loop enabled, and a callback when paused.

PreviousMethodsNextProperties

Last updated 16 days ago