Interactive Music in unity

Hi, I am making an open world shooting game in Unity, and I simply need a background music playing on loop, and another combat music that will start playing when player come close to an enemy. How can I achieve that? I am new on fmod and I have seen many tutorials but they are all overcomplicated with scripts and parameters.

This behaviour is best achieved using parameters, but you don’t neccessarily need to use scripts.
In the Example project that you downloaded with FMOD Studio there is an event, “Music/Level 02”, that already has the neccessary parameters setup. If you play this event in FMOD Studio, you can see that changing the “Area” parameter on the right changes the volume of each track, making the music more or less intense as required.


To use this event in Unity, you will need to link your Untiy project to the FMOD Studio Example Project in the FMOD Settings.

Now in Unity, you can add an FMOD Studio Event Emitter component to an empty game object. On that component set the Play Event to “Object Start” and set the Event to “event:/Music/Level 02”. This will allow the event to start playing as soon as the scene starts running.
image

To change a parmeter when the player gets close to an enemy, you can use a FMOD Studio Parameter Trigger along with a sphere collider to register when the player is within range. To do this you will need the following:

  • An enemy with a collider on it, with Is Trigger enabled, and two FMOD Studio Parameter Triggers; one for trigger enter to increase the music intensity, and one for trigger exit to bring it back down again.
  • A reference to the game object containing the Studio Event Emitter as the Target on each Parameter Trigger, and with the Collision Tag set to “Player”
  • A player, tagged with the “Player” tag, and a rigidbody attached to trigger the parameter trigger

Here is a screenshot of the required setup for clarity:

Now when running the scene and moving the Player into the Enemy’s sphere collider, you should hear the music changing in intensity.

thank you! I will try that