SoundParameter

Use SoundParameters to control sounds through code

SoundParameters are used to control how SoundEvents are played (e.g. volume, polyphony, fade in length etc). They can be passed when playing a SoundEvent and set to update either once or continuously. They have similar functionality as the modifiers, but with scripting capabilities.

Example code:

using UnityEngine;
using Sonity;

public class ExampleSoundParameter : MonoBehaviour {

    public SoundEvent soundEvent;
    SoundParameterVolumeDecibel volumeParameter = new SoundParameterVolumeDecibel(0f, UpdateMode.Once);

    void Start() {
        // Sets the volume parameter to a random value between -12 dB and 0 dB
        volumeParameter.VolumeDecibel = Random.Range(-12f, 0f);

        // Plays the SoundEvent with the sound parameter
        soundEvent.Play(transform, volumeParameter);
    }
}

Update Modes The UpdateMode enum determines if the SoundEvent will take the parameter into consideration only once at start or if it will be updated continuously.

// The SoundParameter will update only once
UpdateMode.Once

// The SoundParameter will update continuously
UpdateMode.Continuous

Parameter Types The parameter type determines which parameter of the SoundEvent will be controlled. See modifiers for more detailed info on the individual parameters.

Last updated