Hi all ,
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