Sound not being triggered in Unity

Hi all :slight_smile: ,

I´m trying to play a Oneshot sound when an enemy is defeated (parameter HP <=0).
I´ve added a component FMOD emitter to the enemy object and a FMOD parameter trigger as well.
The enemy object has a rigibody 2D and a Collision 2D components.

My approach to play the sound was:

FMOD event emitter
Play event: Collision 2D Enter
Stop event: Collision 2D Exit.
FMOD parameter trigger
Target: The enemy (who´s also the emitter).
Collision tag: Enemy (the same of the game object).
Trigger: Trigger enter 2D.
event parameter (HP) is active and set to 0.

Thing is the sound is not playing.

I thought that maybe FMOD is not getting right the stat of the HP so the program is unable to understand when the sound must be triggered.

This is the code of the HP stat:

public class Stats : MonoBehaviour
    {
        //Death event call when player or somebody hp <= 0 
        public delegate void DeathEvent();
        public DeathEvent OnDeath;

        public StatsData statsData = new StatsData();

        //Damage method
        public void GetDamage(float damage)
        {
            statsData.HP -= damage; //Subtract damage from hp

            if (gameObject.tag == "Player") //if player
                UIManager.Instance.UpdateHP(statsData.HP); //Update UI

            if (statsData.HP <= 0) 
            {
                Death();
            }
        }

        //Death method
        public void Death()
        {
            OnDeath();
        }

    }

Any help?

Thank you :slight_smile:

You cannot have two components on a single game object with one set to Trigger and the other set to Collision because Triggers and Collisions are mutually exclusive in Unity. I’m guessing no sound is playing because you have Is Trigger ticked on the collider, and therefore no “Collision Enter 2D” or “Collision Exit 2D” events can occur to start the Event Emitter.
Here are your options to get this working:

  • Have both components use “Trigger Enter” and tick Is Trigger on the collider.
  • Have both components use “Collision Enter 2D” and untick Is Trigger on the collider.
  • Create two separate game objects childed to a single parent game object
    • One with the Parameter Trigger set to “Trigger Enter” and Is Trigger ticked on the collider
    • One with the Event Emitter set to “Collision Enter 2D” and Is Trigger unticked on the collider
1 Like