Knowledgebase / How to use music in your game
Sounds and music add depth to a game. You can add sound effects and music tracks to your games by following these steps:
1. Upload the music or sound effect
Make sure the audio file is an mp3 file, and isn’t too large. Here’s a sound effect and music track to get you started:
Open the Asset Manager by clicking on “Assets” in the top right of the screen.
Create a new pack or select a pack you own and click the “Create New Asset” button. Select “sound/audio” and upload the music you want to use.
2. Make a script to play the sound/music
Next, you’ll need a script to trigger the sound to play. We’ll make this script attached to a game object in your level, and the script will make the game object play the sound. Right-click on an object in your level, and select Add Script.
You only need a couple of blocks in this script: When created (from Events), and either the “play sound effect” block or “play music” block (both are from Sounds).
The “play sound effect” block will play audio once until it finishes. The “play music” block will play audio and loop it over and over again.
Here’s how the script should look. It simply plays some music when the object the script is attached to is created.
Open the Script Properties (the button with three lines in the top-left corner), then give your script a name, and most importantly, make sure that the sound variable has “Public” ticked.
3. Select the music/sound effect from the object’s properties
The only thing left to do is to choose the music/sound effect on the game object’s properties. Right-click the object and select “Edit Instance Properties.”
Then select the music you want to play from the drop-down;
And that’s it! You’re all set. Hit Play and enjoy the sweet serenade of your in-game music and sounds.