Getting Pick up to Play audio in Roll A Ball Tutorial

Hi everyone, I’m just started doing some of the Tutorials on the Unity site and finished Roll A Ball. I wanted to take it a step further and add a pick up SFX when the cubes get acquired. I looked at a few posts inquiring about the same issue and tried to insert that code but wasn’t successful. I was wondering if anyone can help me in the context of the Roll A Ball code.

I have 1 audio source attached to the Pick up Prefab so that it spreads across all Pickups. Attached is the code.


1)You need to add a public audio source call it audio1

2)Say audio1=GetComponent.Play();
put this on line 36

If you want and you have time pass to my channel you can find interesting feature

Hi UnityGamelta,

Thanks for the help. A few questions for you as I’m embarrassingly new to C#.

  1. What goes in between public and audio1; to instantiate it at the top?
  2. Does anything else need to be added in front of audio1 in line 36?

Thank you!