Unity's added background music and slider controls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.