How to Control Audio by Slider UI unity?

Hello everyone.I want to write a apps like media player.
I want to use new UI Slider of Unity to control audio.We can drag slider to change time play music like as Media player.
I only find that change volume audio by slider.can someone help me? Thank you so much.

Just create a script with a method that has a float parameter, in that use the parameter for the properties of the media player you want to control.
Then simply hook that script up to a gameobject (with the media player) and then call it from the OnValueChanged event of the slider using a dynamic property.

For example:

using UnityEngine;
using System.Collections;

public class AudioVolume : MonoBehaviour {

    AudioSource source;
    // Use this for initialization
    void Start () {
        source = GetComponent<AudioSource>();
    }
   
    public void SetVolume(float value)
    {
        source.volume = value;
    }
}

1 Like

Is there any way doing this to change all audio sources without referencing them in the editor, so finding them automatically and changing them all with 1 slider?

Hmm, if you want to change the volume of all audio sources in the scene why don’t you use an audio mixer and use the slider to control the audio mixer volume then?