Opening document…

The interface could not load. You can still read below. Retry

3 Create Actions and Control Volume with a Variable

Before you start: Confirm that Explorer → Assets → Layer → Gameplay contains the SFX_Ball_Roll_Loop Sound and the SFX_Ball_Pickup container.

The looping Sound, container, and three child Sounds in Gameplay

Create Three Actions#

An Action is an entry point you can execute: a Play Action starts a sound, and a Stop Action stops it. Sounds and Containers still define the audio content and playback rules. Unity will use these three Actions to control the game audio.

  1. In the Explorer, right-click the SFX_Ball_Roll_Loop Sound and choose New Action → Play.

    image.png

  2. Right-click the same SFX_Ball_Roll_Loop Sound again, this time choosing New Action → Stop.

    image.png

  3. Under Action in the Explorer, confirm that Play_SFX_Ball_Roll_Loop and Stop_SFX_Ball_Roll_Loop appear.

    The unsaved Play and Stop Actions
  4. Return to Layer → Gameplay, right-click the SFX_Ball_Pickup container, and choose New Action → Play.

    image.png

  5. Under Action, confirm that the third object is named Play_SFX_Ball_Pickup. This Action plays the Random container configured in the previous chapter.

    image.png

Audition the Three Actions Individually#

  1. In Explorer → Action, select Play_SFX_Ball_Roll_Loop and press Space. You should hear the loop start.

    image.png

  2. While the loop is still playing, select Stop_SFX_Ball_Roll_Loop and press Space to execute this Stop Action. Confirm that the loop stops.

    image.png

  3. Select Play_SFX_Ball_Pickup and press Space. Wait for the sound to finish, then trigger it a few more times to audition the random variations. Each trigger should play only one sound.

    image.png
  4. Press Ctrl+S to save the project.

Create BallSpeed to Control Volume with a Variable#

As the ball accelerates, its rolling sound should become louder. The audio system first needs to know how fast the ball is moving before it can determine how loud the sound should be. A Variable is a project object that passes values of this kind. Name this one BallSpeed.

Think of BallSpeed as a speed knob that the sound's playback rules can read. This tutorial maps speed to 0–1: 0 means stopped, 1 means the speed chosen for full volume, and 0.5 means half that speed. These values are neither actual speed units nor volume percentages.

The variable supplies the input; the binding curve determines how that input affects volume. You will bind BallSpeed to the Volume of SFX_Ball_Roll_Loop: an input of 0 corresponds to −24 dB, an input of 1 to 0 dB, and intermediate values are calculated from the curve.

In this chapter, adjust this knob manually in Studio's Control panel and listen to the volume changes. After connecting Unity in Chapter 7, the script will read the ball's speed and update BallSpeed. Naming a variable BallSpeed does not make it detect the ball's speed automatically; the two Actions created earlier still start and stop the loop.

Create and Configure the Variable#

  1. Find Variable under Explorer → Assets on the left of the main window.

    image.png

  2. Right-click Variable and choose Create → Variable → Smooth.

    Why choose Smooth? The ball's speed is not limited to stopped and moving; it also passes through intermediate speeds. Smooth accepts continuous values such as 0.1, 0.25, and 0.5, making it suitable for controlling volume with speed. Step is better for categories represented by discrete values, such as 0 and 1 for two ground materials.

    Creating a Smooth Variable
  3. Name the new variable BallSpeed.

    image.png

  4. Select BallSpeed and find Range under Inspector → Basic → Identity on the right. The right-hand field currently shows 100; change it to 1. Range defines the variable's allowed values: in this exercise, the minimum is 0 and the maximum is 1.

    The Identity section and Range setting for BallSpeed
    Changing the upper end of Range to 1
  5. Find Default Value below and change it from 0 to 1. Default Value is the value used when the variable is initialized.

    image.png
    Setting Default Value to 1 for this exercise

Bind BallSpeed to the Sound's Volume#

  1. Return to Explorer → Layer → Gameplay and select SFX_Ball_Roll_Loop.

    image.png

  2. Find Volume under Inspector → Basic → Playback on the right. Click the binding button at the right end of the Volume row, then choose Select Variable from the menu.

    image.png

  3. Find BallSpeed in the Variable selection window and double-click it to open the External Editor.

    image.png
image.png

Set the Volume Curve from −24 dB to 0 dB#

  1. The horizontal axis represents the BallSpeed input over a range of 0–1; the vertical axis represents the Volume gain adjustment in dB. In the External Editor curve graph, move the pointer onto the small circular point at the far left, then right-click and choose Enter Coordinates....

    image.png

  2. In the coordinate fields that appear, leave X at 0, enter −24 for Y, and press Enter.

    image.png
    image.png

  3. Move the pointer onto the small circular point at the far right, then right-click and choose Enter Coordinates....

    image.png

  4. In the coordinate fields that appear, leave X at 1, enter 0 for Y, and press Enter.

    image.png
    image.png

  5. Confirm that the curve connects (0, −24 dB) on the left to (1, 0 dB) on the right. Only change the two existing endpoints; you do not need to add control points.

  6. Click the close button at the upper right of the External Editor window to return to the Studio main window.

    image.png

Change the Variable in Control and Audition#

  1. In Explorer → Action in the main window, select Play_SFX_Ball_Roll_Loop.

    image.png

  2. If the Control panel is not visible at the bottom of the main window, click the middle of the three panel icons at the upper right.

    image.png

    Alternatively, choose View → Control at the top of the main window. Either method opens the panel.

    image.png

  3. Control appears at the bottom of the window. If the panel is too short, move the pointer to its upper edge, hold the left mouse button, and drag upward until the variable row is fully visible.

    image.png

  4. Confirm that the Control title shows Play_SFX_Ball_Roll_Loop and that BallSpeed appears on the left. Return to the Explorer, select this Action, and press Space to start the loop.

    image.png
    image.png

  5. While the loop plays, slowly drag the BallSpeed → Value slider on the left of Control and compare the volume at different values. Dragging left makes the sound quieter; dragging right makes it louder. At the far left, the volume is at its minimum.

    image.png

  6. Value on the left is the variable input; Value in the property table on the right is the corresponding Volume value. An input of 0 should show −24 dB on the right; an input of 1 corresponds to 0 dB.

    image.png
    image.png

  7. When you finish comparing, set the BallSpeed input on the left back to 1. Then click the red square Stop button at the top of the main window to stop audition playback.

    image.png
    image.png

  8. Press Ctrl+S to save the project.

Chapter check: You have auditioned all three Actions. BallSpeed has a range of 0–1 and a Default Value of 1. The Volume curve runs from (0, −24 dB) to (1, 0 dB). The Control input is back at 1, playback is stopped, and the project is saved. Continue to Chapter 4: Install Unity and Prepare the Roll-a-Ball Project.