Can you elaborate on “it’s not working”? Are you getting any errors? Or no errors, just nothing plays?
Is there an audio clip loaded for each object? Have you set up “thePlayer” and “theBall” references in the inspector? (i.e. drag these objects in via property inspector)
In order for your Audio Source to know what to play, it has to have an audio clip loaded somewhere. An “audio clip” is a sound file. Put another way… if you don’t tell your source what to play, how can it play anything?
See this doc here:
The audio clip is the first thing listed on the Audio Source. (Or you can load an audio clip via code)
My next thought here is that you have it playing every frame without checking if it’s already playing, so I think it’s interrupting itself. Check to make sure it’s not already playing first, or figure out a way to do it so that it doesn’t keep replaying every frame.
When you call “Play” it will stop whatever is playing on that audio source and play the clip you provide… so in this case, I think it just keeps restarting every frame.