Sound not played when collecting Coin

145 views Asked by At

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.

CoinCollect game object

Inspector View of CoinCollect, as can see CoinSFX is applied on AudioClip property

enter image description here

Coin Object look like this at inspector view and my AudioSource applied there in scripts. Also check Is Trigger checkbox

enter image description here

Player Inspector View

enter image description here

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.

1

There are 1 answers

0
Zong On BEST ANSWER

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

enter image description here