I have been facing an audio issue for 3days. I was looking to play audio after the collision. Not getting any proper idea OR where the problem occurs in my scenario, I could not solve my problem. In my GameObject, I added Audio Source through 'Add Component' where I put my mp3 file into AudioClip and also checked off 'Play On Awake'.
NB : PlayExplosionAnimation() and Destroy() are working fine.
public class Player : MonoBehaviour
{
private AudioSource source;
void Start()
{
source = GetComponent<AudioSource>();
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Rocks")
{
source.Play();
PlayExplosionAnimation();
Destroy(gameObject);
}
}
}