Search documentation

Search documentation pages and sections

Get it

Single Sound — Common Use Cases

Practical examples for standalone effects registered outside any collection.

Overview

SingleSound is the right choice when a clip stands on its own — UI feedback, player actions, level music, and other one-off sounds. Each example below assumes you already have a reference assigned in the Inspector or retrieved with GetSingleSound.

For method signatures and parameter details, see the API Reference.

UI Button Click

A single click sound shared across menus is one of the most common uses for SingleSound. Assign the reference once and call Play() from your button handler — no per-button clip setup required.

Example

C#
public SingleSound buttonClick;

public void OnButtonPressed()
{
    buttonClick.Play();
}

Player Jump

Jump sounds repeat constantly during gameplay. PlayRandomPitch adds subtle variation on each jump so the effect feels less repetitive without maintaining multiple clips.

Example

C#
public SingleSound jumpSound;

void OnJump()
{
    jumpSound.PlayRandomPitch(0.9f, 1.1f);
}

Background Music

Level or menu music registered as a single sound can fade in when a scene starts and fade out when the player leaves. Use FadeIn to ramp volume up smoothly and FadeOut to avoid an abrupt cut when transitioning.

Example

C#
public SingleSound backgroundMusic;

void StartLevel()
{
    backgroundMusic.FadeIn(2f, 0.7f);
}

void EndLevel()
{
    backgroundMusic.FadeOut(1.5f);
}

Pause and Resume

When the game pauses, hold a looping ambient or music track at its current position with Pause(). Resume playback from the same spot when the player returns — no need to track elapsed time yourself.

Example

C#
public SingleSound ambientLoop;

void OnGamePaused()
{
    ambientLoop.Pause();
}

void OnGameResumed()
{
    ambientLoop.Resume();
}

Item Pickup

Pickup sounds are short one-shots triggered on collision or interaction. Pass explicit volume and pitch to make rare items feel more rewarding — a slightly higher pitch draws attention without needing a separate clip.

Example

C#
public SingleSound itemPickup;

void OnTriggerEnter(Collider other)
{
    if (!other.CompareTag("Player"))
        return;

    itemPickup.Play(1f, 1.2f);
}