Search Unity

How to fade music from a specific volume

Discussion in 'Scripting' started by kevcool100, Dec 18, 2014.

  1. kevcool100

    kevcool100

    Joined:
    Nov 4, 2014
    Posts:
    1
    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 :D) 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 :)
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    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.
     
  3. SeasiaInfotechind

    SeasiaInfotechind

    Joined:
    Nov 17, 2014
    Posts:
    32
    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