Hi! So I'm trying to make a flappy bird game and I want a sound effect to play when I die. This was my function for dying (this is in the logic script): Code (CSharp): public void gameOver() { gameOverScreen.SetActive(true); } So I went and added an Audio Source component in my logic game object and placed my mp3 file "NEILSCREECH". So I called it on the logic script: Code (CSharp): public AudioSource NEILSCREECH; and changed the function a bit: Code (CSharp): public void gameOver() { gameOverScreen.SetActive(true); NEILSCREECH.Play(); } So I ran the game and when I hit something that would kill me, it wouldn't play anything. It just gave the error code: ArgumentNullException: Value cannot be null. Parameter name: source Also, I found that if the play on awake setting on the Audio Source component is turned on, it would play, but it would still error on the pipes. How can I fix this?
It's always the same, always!! How to fix a NullReferenceException error https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/ Three steps to success: - Identify what is null <-- any other action taken before this step is WASTED TIME - Identify why it is null - Fix that
LOL ok it's a dumb mistake but there was a step I didn't know (to drag the audio source component to the slot on the script). Thank you!