Opening document…

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

7 Add Components and the Audio Script

Before you start: Complete the Pack export in Chapter 6, then return to the Unity project.

Add Two Components from the Unity Integration Package#

  1. After installing the Unity Integration Package, you can find HarkenAudioSystem and HarkenListener through Unity's Add Component search. You do not need to download their scripts separately. In the Hierarchy window at the upper left of the Unity main interface, select Player under the Roll-a-ball scene.

    image.png

    Find the Inspector on the right and scroll to the bottom to locate Add Component. Click it and search for HarkenAudioSystem. Click Harken Audio System in the results to add it to the Inspector. This component starts the Harken audio runtime, loads the Packs configured earlier, and provides a common entry point for the audio script you will add later.

    image.png
    image.png

  2. Return to the Hierarchy window at the upper left and select Main Camera.

    image.png

    In the same way, search for HarkenListener through Inspector → Add Component on the right. Click Harken Listener in the results to add it to the Inspector.

    image.png
    image.png

    In Harken Listener, click the circle button at the far right of Runtime. On the Scene tab, double-click Player. Runtime should then display Player (Harken Audio System).

    image.png
    image.png
    image.png

Import the Provided Script and Fill In the Names#

After confirming that the Unity Integration Package is installed, both paths are configured, and the Packs have been exported, import the script below.
Click the following link to download it.

Download HarkenBallAudio.cs
  1. In the Project window at the bottom of the Unity main interface, find Assets/UnityTechnologies/RollABall/Scripts.

    image.png

    Drag the downloaded HarkenBallAudio.cs into this folder.

    image.png

  2. Return to the Hierarchy window above, select Player (the ball) under the Roll-a-ball scene, and add HarkenBallAudio through Add Component.

    image.png
    image.png
    image.png

  3. In the newly added Harken Ball Audio component, the three Action names and one Variable name are initially blank. Fill them in using the objects created in Chapter 3. The left column shows the Inspector labels, with script field names in parentheses. Copy the complete strings from the value column without backticks or quotation marks. If you reuse an existing component, old serialized values may remain; check each field against the table.

    These four names must exactly match the corresponding Action and Variable object names in Studio, including capitalization, underscores, and spaces. Even changing a single letter's case may prevent the object from being found, so sounds may not trigger or the speed variable may not update. For example, BallSpeed must not be entered as ballspeed. If you rename an object in Studio, update its corresponding field in Unity too. Copy the actual object name rather than typing it manually.

    image.png

Inspector Field

Value

Corresponding Object or Meaning

Pickup Action (pickupAction)

Play_SFX_Ball_Pickup

Action that plays the Random container

Roll Start Action (rollStartAction)

Play_SFX_Ball_Roll_Loop

Action that starts the rolling loop

Roll Stop Action (rollStopAction)

Stop_SFX_Ball_Roll_Loop

Action that stops the same rolling Sound

Speed Variable (speedVariable)

BallSpeed

The Smooth variable from Chapter 3

Full Volume Speed

3

Planar speed that maps to a variable input of 1, in Unity distance units per second

Speed Smooth Time

0.1

Input smoothing time in seconds

What this script does: It prepares and resolves the three Actions, creates an emitter that follows Player, calls the corresponding Action once when rolling starts or stops, continuously maps planar speed to the global BallSpeed variable, and calls the pickup Action when entering a Pick Up trigger. It does not handle movement, counting, or hiding pickups; the original PlayerController still does those jobs. The script does not initially contain your object names, so you must fill in the four name fields in the table.

How the two numeric settings affect the sound: A higher Full Volume Speed produces a lower BallSpeed for the same actual speed, so the ball must move faster to reach the curve's 0 dB endpoint; it does not change the ball's movement speed. A higher Speed Smooth Time makes gain follow acceleration and deceleration more slowly; it does not change the curve's shape. Keep 3 and 0.1 for the first check in the next chapter before comparing other values.

  1. Open Window → General → Console from Unity's top menu, or click Console in the lower part of the main interface.

    image.png
    image.png
  2. Next, click Play at the top of Unity and watch the Console output. When HarkenBallAudio: ready. appears, audio initialization is complete.

image.png
image.png

You can click the stop button at the top now, but leave the Unity project open. The next chapter covers auditioning.

image.png

Chapter check: Player retains its movement script and has Harken Audio System and Harken Ball Audio. The camera Listener's Runtime references Player, and all four name fields are filled in.