Skip to main content
โ€น Back to Tutorials
Intermediate Unity

Unity 3D & Playmaker - Setting sound volume with UI Slider and turning sound On/Off with a UI Toggle

Apr 8, 2021
About this tutorial

In this tutorial, we will tackle using the UI Slider and UI Toggle to change volume and to turn the sound On / Off using Unity 3D and Playmaker. Super EASY!! Also check out How to Make a Bounce Game Series https://bit.ly/39HIYBU. ๐Ÿ‘‰๐Ÿผ To Sign up for email updates on my latest tutorials and game pr

Written Guide

This tutorial builds a reusable sound manager in Playmaker with two controls players expect: a slider to set music volume and a toggle to mute. It covers both the UI side โ€” restyling Unity's default slider and toggle with custom sprites โ€” and the Playmaker logic that connects those controls to an Audio Source.

Build and skin the volume slider

Add a UI > Slider into your sound panel and size it up (around 300x50). Swap the default art for your own: drop a darker sprite into the Background image and a custom sprite into the Fill. A useful trick for the fill โ€” set its mesh type to Full Rect and, in the Sprite Editor, define a 9-slice border so the ends keep their size while the center stretches. Replace the handle sprite and scale it up slightly (about 1.3) so it isn't squished.

Build and skin the mute toggle

Add a UI > Toggle named volume on/off and size it (around 300x60). Replace its Background with a custom checkbox sprite (around 50x50) and its Checkmark with your own check sprite at a matching size. Set the label to white so it reads on the dark panel, bump the font to about 30, change the text to 'sound on/off', and nudge everything to center cleanly.

Set up the audio source

Create an empty Game Manager with a child empty named Sound Manager to keep things organized. Add an Audio Source to the Sound Manager, drag your music into its Audio Clip, and enable Loop since it's background music. Pressing play should confirm the track plays โ€” this single source is what the UI will control.

Wire volume to the slider

Add a sound volume FSM to the Sound Manager. Drag the Audio Source in and add Set Audio Volume, feeding it a new variable sound volume rather than a fixed number, updated every frame. Lock the FSM, then drag the slider in and add UI Slider Get Value (also every frame), storing into that same sound volume variable. A slider returns a normalized 0-to-1 value, so half-way reads 0.5 โ€” order the Get Value before the Set Volume so the audio always uses the latest reading.

Wire mute to the toggle

Add a second FSM, sound mute, with two states (Sound On, Sound Off) and matching events, transitioning between them. In each state, drag in the Audio Source and add Audio Mute โ€” unchecked in Sound On, checked in Sound Off. Lock the FSM, drag in the toggle, and use Set Value to match the visible check state plus the On Toggle Value Change event to send the opposite state's event. Copy the block to the other state and reverse the values, giving you a toggle that mutes and unmutes while keeping the checkbox in sync.

Unity tools by Bliz Studio
Built for our own games — now on the Asset Store

Multi Tag — unlimited hierarchical tags for any GameObject. Hierarchy Pro — style your whole hierarchy with rules. Made by a Unity dev, for Unity devs.

Explore our Unity assets →