How to fade music from a specific volume

Hello there!

I am currently creating a 2D game in which I have created a menu (without using GUI) and my problem is that when I clic the “Play” button I want the music’s volume (of AudioSource) in the menu to fade to 0, but it is already set to 0.17 (the music is too loud). I did search on the internet, but the only scripts I found wouldn’t work or were too complicated to modify anything.

What I am asking for is a script that make music fade (if you can :smile:) and (PLEASE) explication on what is what and what it does! Also, I would like the script to contain variable (or anything) that will allow me to change the fadin time, volume, etc.

Thank you for answers :slight_smile:

You should be able to lerp the volume of the audiosource. I would suggest looking it up in the script reference. Lerp is very handy for many things.

Hi,

There are basically two approaches to find the solution.

  1. Edit your sound file using sound editor tool and minimize its sound pitch.
  2. Try to set volume property in audio source component.

Thanks