Search Unity

Question Flappy sfx

Discussion in '2D' started by TokoHagar, Jun 4, 2023.

  1. TokoHagar

    TokoHagar

    Joined:
    Apr 29, 2023
    Posts:
    9
    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):
    1. public void gameOver()
    2.     {
    3.         gameOverScreen.SetActive(true);
    4.     }
    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):
    1.  public AudioSource NEILSCREECH;
    and changed the function a bit:
    Code (CSharp):
    1. public void gameOver()
    2.     {
    3.         gameOverScreen.SetActive(true);
    4.         NEILSCREECH.Play();
    5.        
    6.     }
    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?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    TokoHagar likes this.
  3. TokoHagar

    TokoHagar

    Joined:
    Apr 29, 2023
    Posts:
    9
    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!