I'm trying to play a sound when an enemy is destroyed. I created a child game object and put this in the OnEnterCollision2D
function:
private void OnCollisionEnter2D(Collision2D collision)
{
effect = GetComponent<AudioSource>();
effect.transform.parent = null;
effect.Play();
Destroy(effect.gameObject, 1);
Destroy(gameObject);
}
However, it doesn't seem to fire this event when the bullet enters the enemy character.