We have two OnCollisionEnter2D methods. One is in the Ball script, which plays a random collision sound. The other one is in the Block script, which plays a breakSound using an AudioSource.PlayClipAtPoint() comment.
So my question is, why can we only hear the breakSound audio (in the Block’s script), and not the random one (in the Ball’s script)?
Hi Almog,
That’s a good question. Are your sound clips loud enough?
Oh my bad
I just tried to set the breakSound further away from the camera so it will be quieter, and now I can hear the random sound. Guess the breakSound was louder so I didn’t hear the random sound.
This makes me think, is there a way to only make the breakSound to work?
Thank you so much for your response!
This makes me think, is there a way to only make the breakSound to work?
Sure. In the ball’s OnCollisionEnter2D method, you could check if the other game object has got a Block component attached. If it has, you don’t play sound clip of the ball.
How can I do that? What line of code can I use?
For example:
Block block = {yourVariableNameInTheParenthesesOfTheMethod}.gameObject.GetComponent<Block>();
if (block != null)
{
// code for playing the sound
}
Excellent! Thank you so so much!
This course is great so far and this community and this forum make it so much better. thanks again.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.