Hey. So I’ve decided to use Audiosource.PlayClipAtPoint for all sounds because it seems I’ll have more control over when sounds play that way. I want to use a sound for when the ball hits the paddle only, which I’ve written in the Paddle script. The only problem is it plays when the game starts! I figure I need to use “if (hasStarted)” like shown in the lecture, but of course hasStarted in the Ball script! I’ve looked around online and found that in order to access the Ball script I need to type “ball = gameObject.GetComponent()”, but it’s saying “the name “hasStarted” does not exist in the current context”. I’ve tried typing ball.hasStarted, and making a “private bool hasStarted”, but they don’t work either. Anyway, here’s my Paddle script:
Update: After looking it up apparently the way I suggested isn’t the optimal way and is slow, hopefully someone else will have a better answer for you.
Thanks for the reply. Unfortunately it didn’t even work, let alone be slow. Having said that I do get one less error in the console when I use FindObjectOfType. Didn’t notice this before, but the error I’m getting in the console is: “‘Ball.hasStarted’ is inaccessible due to its protection level”. Hold on a minute…
It’s working! I changed the hasStarted variable in the Ball script to public and it works! Thanks my man. Still, if anyone can suggest a way that’s quicker, that would be great to. Tried to follow the first answer in that link, didn’t really get it hehe. Still, I’m happy that it’s working for the moment.
This is still odd. I liked your idea so much that I added a sound to paddle myself!, modeling after the brick sound, and it works fine. I wonder if its your placement of the OnCollision… statement function. i placed mine after the closing curlies of update and before Autoplay(). Perhaps you are testing if the paddle is coliding, and it is, too soon.
I don’t really understand what you’re saying. It’s all working fine for me now. Are you saying you’re not having the problem of getting the ball hitting the paddle sound as soon as the level starts? In any case I’m glad I… inspired you. Haha.