The PlaySound() function allows you to play sound effects at any moment during the game.
Sounds are loaded directly from the project’s assets/sounds folder.
PlaySound(filename, volume = 1.0)
"explosion.mp3").0 (silent) and 1 (full volume). Default is 1.0.// Play a sound at full volume
PlaySound("explosion.mp3");
// Play a softer sound
PlaySound("laser.wav", 0.3);
You can call PlaySound() from any lifecycle function, such as
OnCollisionEnter() or OnTriggerEnter().
function OnTriggerEnter(obj, other) {
if (other.name === "enemy") {
PlaySound("explosion.mp3", 0.7);
Destroy(other);
}
}
Each call to PlaySound() creates a new audio instance,
allowing multiple overlapping sounds without interruptions.
// Fire multiple sounds without cutting the previous ones
PlaySound("shot.wav");
PlaySound("shot.wav");
PlaySound("shot.wav");
Audio() API, so manual preloading is unnecessary.Audio object, allowing you to control it manually if needed.// Store the reference and manually stop the sound
const audio = PlaySound("engine_loop.mp3", 0.5);
audio.loop = true;
// Stop after 5 seconds
setTimeout(() => audio.pause(), 5000);
PlaySound() is ideal for fast effects such as shots, explosions, and UI clicks.Audio object for advanced control.