I am new to game development and building Endless Runner game, where Rocky(Player) can collect coins, and I applied cool sound effect when coin is being collected by player but that is not played. Here is the detail what I did so far,
First I create an Empty Object named it CollectCoin and drop coin collect sound on it.
Inspector View of CoinCollect, as can see CoinSFX is applied on AudioClip property
Coin Object look like this at inspector view and my AudioSource applied there in scripts. Also check Is Trigger checkbox
Player Inspector View
And finally my Class
public class CoinCollect : MonoBehaviour
{
public AudioSource coinFX;
public void OnTriggerEnter()
{
coinFX.Play();
this.gameObject.SetActive(false);
}
}
What and where i done wrong so far? I am stuck here since yesterday. Please help me.
There was nothing wrong with my script, and I dragged both Coin Collect Sound and Background Music at correct place, problem was with my Unity, I don't know when I muted "Mute Audio" option in unity, or its muted by default i have no idea but my problem is resolved. That is why my sound was not playing