# Interactive Music in unity

**URL:** <https://qa.fmod.com/t/interactive-music-in-unity/18509>\
**Category:** Unity\
**Tags:** unity\
**Created:** [March 12, 2022, 6:42pm UTC](https://qa.fmod.com/t/interactive-music-in-unity/18509 "2022-03-12T18:42:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![QuantumMobileGames](https://avatars.discourse-cdn.com/v4/letter/q/9d8465/32.png) [@QuantumMobileGames](https://qa.fmod.com/u/QuantumMobileGames)\
**Post date:** [March 12, 2022, 6:42pm UTC](https://qa.fmod.com/t/interactive-music-in-unity/18509/1 "2022-03-12T18:42:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [March 15, 2022, 11:22pm UTC](https://qa.fmod.com/t/interactive-music-in-unity/18509/2 "2022-03-15T23:22:53Z")

</div>

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.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/1/19bb0ca54d58a0de2983889b954dd65002d758db.png)  
To use this event in Unity, you will need to link your Untiy project to the FMOD Studio Example Project in the FMOD Settings.  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/a/aa0f350406b549e151dac48a50b581c3e757dc3d.png)

Now in Unity, you can add an [FMOD Studio Event Emitter](https://fmod.com/resources/documentation-unity?version=2.02&page=game-components.html#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](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/2/2628b7c3e0b6386633e1c2754e8466b8c555ee20.png)

To change a parmeter when the player gets close to an enemy, you can use a [FMOD Studio Parameter Trigger](https://fmod.com/resources/documentation-unity?version=2.02&page=game-components.html#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:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/0/0e846658877555bf0c5412448df7f006eec00000.png)

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

---

<div class="post-metadata">

**Author:** ![QuantumMobileGames](https://avatars.discourse-cdn.com/v4/letter/q/9d8465/32.png) [@QuantumMobileGames](https://qa.fmod.com/u/QuantumMobileGames)\
**Post date:** [March 26, 2022, 10:54pm UTC](https://qa.fmod.com/t/interactive-music-in-unity/18509/3 "2022-03-26T22:54:49Z")

</div>

thank you! I will try that
