[Solved] < 2 Sounds at the same time >

Hi

I have and issue with the “boing” and “crack” sound clips. they sound simultaneously. I tryed to destroy the boing AudioClip whenever it hit a brick, or make an If statment for the tags so that the Boing does not sound with the bricks but I haven’t been able to put that in to code, could someone help me out or share your solutions.

Thanks

Heading

I just want to say I’ll be doing that section of the course tomorrow - hopefully - so, I’ll report what happens when I get to it, and tell you if I’m also getting the two sounds playing at once and also if I find a way around it - but I’m pretty much a noob. So don’t count on too much :stuck_out_tongue_closed_eyes:.

Cheers.

1 Like

Ok, here’s what I’ve done I’ve made a boing sound only play when it hits the paddle/bat/ship. The way I did that was to use a game tag on the whatever you call it like in my case “myBat”. This sound is the attached AudioSource. Then on the “Breakable” objects ie the bricks use the playAtClipPoint with the overloaded volume control,so, it doesn’t blow my ears out :grimacing:. This sound was attached programmatically as per the lecture.

For a different sound when the bricks are destroyed, I’ve used a sound on the “smoke” prefabs that we make in a couple of lectures from now. That way you can have a different sound on that as well. Haven’t changed all of them yet in case a better way turns up - I have a question pending on the forum and hoping that someone answers it.

if (hasLaunched) 
	{
	if (coll.gameObject.tag == "myBat")
		{
		float distanceX=(this.transform.position.x - 
				                 	myPaddle.transform.position.x);
		Debug.Log("Batter Up: "+distanceX);
		audio.Play ();
		}
	if(coll.gameObject.tag == "Breakable")
		{
		AudioSource.PlayClipAtPoint(brickHit ,transform.position, .2f);
		}
	}//*/

Now that’s probably as clear as mud - and my brain has turned to mush from the different ways sound are attached to scripts and object and how you play them :scream:, that I need a good lie down :sleeping:.

If you need more information then ask away and I’ll try and help. Remember I’m pretty much a noob with Unity with this course being my only structured learning.

2 Likes

You may be a noob but you are way better noob than I am, Thank a lot Mr. Vaughan_MacEgan, I really apreciate you took the time to answer my question and help me out, it was just this line of code that I wasn’t sure how to make it work

“if ( collision.gameObject.tag == “Walls”)”

I created a tag for the walls and paddle so it only play the clip when hitting them.
Thanks again, Now I can progress with the lectures. Let me now if you post a game I will be happy to try it out. :grin:

2 Likes

Hi, i know that the question was already solved, but i come with a simple suggestion that is put a new conddition on
the OnCollisionEnter2D in the ball script

if (hasStarted && collision.gameObject.tag != "Breakable")
{
    audio.Play();
}

works for me.
PS: sorry for my c***py english :frowning:

5 Likes

PS: sorry for my c***py english :frowning:

Your English is very good and thanks for contributing with your code solution above :slight_smile:

Thankyou! This worked for me too

1 Like

Privacy & Terms