Search Unity

Audio Audio vary the volume up and down

Discussion in 'Audio & Video' started by MrLeggo, May 10, 2019.

  1. MrLeggo

    MrLeggo

    Joined:
    Feb 16, 2018
    Posts:
    20
    I want to create the effect of a distance radio in the open air, where you hear the volume go up and down as its affected by the wind. does that make any sense?!

    My guess would be to use a sine wave on the volume (between two values), but I'm not sure if its possible and how I would write that!
     
  2. Docaroo

    Docaroo

    Joined:
    Nov 7, 2017
    Posts:
    82
    This should be fairly straight forward .... the property you need to affect is AudioSource.volume where volume is a float between 0.0f and 1.0f .

    Simply have this value changing based on whatever parameter you want (a sin function or directly from some wind strength parameter elsewhere in your game).

    So, in the Update() method you need something like:

    myAudioSource.volume = <new float value>


    Note that the volume is in linear scale not log like dB so usually some conversion from log to linear is required to get it sounding "natural".