The game audio is divided into two kinds: background music and environment music.
Audio clip has four different music formats.
MP3: For longer audio, as background music.
OGG: For longer audio, as background music.
Wav: For shorter audio, as ambient music.
Aiff: For shorter audio, as ambient music.
In the main camera properties, click Add Component to select the audio component, click the audio Source component in the selection. This allows the sound source component to be added to the main camera.
Public classBackmusic:monobehaviour { PublicAudioClip Music; PrivateAudiosource back; voidStart () { back= This. Getcomponent<audiosource>(); Back.loop=true;//Set Loop playbackBack.volume =0.5f;//set the maximum volume, interval between 0-1Back.clip =Music; Back. Play (); //Play background music, }}
Use the UI component Slider to control the volume size:
Public classBackmusic:monobehaviour { PublicAudioClip Music; PrivateAudiosource back; Publicslider Slider; voidStart () { back= This. Getcomponent<audiosource>(); Back.loop=true;//Set Loop playbackBack.volume =0.5f;//set the maximum volume, interval between 0-1Back.clip =Music; Back. Play (); //Play background music } voidUpdate () {Back.volume=Slider.value; }}
Unity's added background music and slider controls