So I followed the lecture step by step, and I made sure that the Audio Listener is enabled on the main camera and removed from the canvas, but the only way I can get the audio to work is by activating Play On Awake, other than that, it doesn’t work on collide.
Here is the screenshot of the code
Here is the audio source for the ball
and the main camera
So, After doing some research, I finally found a Solution, and I will share it in this post so it may help you in the future if you ran into the same issue as I did.
First, create an AudioSource in the public class and give it a name
Like this
Then replace the the the line of code GetComponent().Play(); with the following code:
name of the audio source = GetComponent();
name of the audio source.Play();
it should look like this :
And it should work just fine.