Search code examples
c#slidervolumeunity-game-engine

How Do I Make A Change A Volume With A Slider?


Im currently working on a settings tab for my game and I was wondering How Do You Effect Volume With A Slider?. Now I know this is kind of a vague question, but I couldn't figure out how to break this question into a simpler part

Feedback is always appreciated ;)


Solution

  • Create slider programmatically and give volume control to the slider.

    public float slidervalue=0.0f;
    public AudioSource audiocccenter;
    public AudioClip myaudiocc;
    
    
    slidervalue = GUI.HorizontalSlider (new Rect (padding +370 * wdpi, 440* hdpi, 90 * wdpi, 44* hdpi), slidervalue,  0.0f, 1.0f);
    
    audiocccenter = (AudioSource)gameObject.AddComponent ("AudioSource");
    
    myaudiocc = (AudioClip)Resources.Load ("Clip name");
    audiocccenter.clip = myaudiocc;
    
    audiocccenter.Play();
    AudioListener.volume = slidervalue; 
    

    May be it will help you.