Sound

A Sound is an instance you create from code to play any sound you previously registered in the Audio Creator window, under the Sounds tab. It represents an individual effect— a hit, footstep, button click, or any one-shot SFX.


🛠 How to create a Sound

After you register a sound in Audio Creator, you can call it in code by its tag or by the generated SFX identifier.

new Sound("Jump").Play();

Or, using the SFX enum:

new Sound(SFX.Jump).Play();

If you rename the tag later in Audio Collection, any code reference (SFX.Jump) will break.

You can also store the sound in a variable when you need to control it afterwards:

Sound jumpSound = new Sound("Jump")
    .SetVolume(0.8f)
    .SetLoop(true);

jumpSound.Play();

📝 Advanced example

Sound laser = new Sound(SFX.Laser)
    .SetVolume(0.5f)
    .SetRandomPitch()
    .SetHearDistance(5, 30)
    .SetOutput(Output.SFX)
    .OnComplete(() => Debug.Log("Laser reloaded"))
    .Play();

👉 A laser configured with lower volume, random pitch, 3D sound, and a callback that fires when the clip ends.

Last updated