Play Crack On last brick

How to I make the last brick of the scene play the crack sound when its destroyed? It doesn’t play because the next scene is loaded before it can.

1 Like

Hi @Noah_Seethor,

You could use a Coroutine for this.

You’d want to call the StartCoroutine() method when you have detected its the final block, then, set the yield duration in seconds to be the length of the sound clip in question. Your method call to play the clip is then called after the yield.

Hope this helps but if you get stuck give me a shout, I have some code examples I can dig out for exactly that purpose, along with the smoke puff particle effect.

Hi @Rob. Thanks for the advice. Im actually still quite stuck even after following your instructions

This is my code. (I switched out the audio clip with a string to simplify it)

The compiler is asking me to give the method StartCoroutine some arguments. Could you explain this more in depth?

(This code is in the Brick.cs class and the method is called whenever the breakable bricks are collided)

Sorry if my debug report is a little shabby

1 Like

Hi @Noah_Seethor,

More than happy to help. You are very close, so well done.

Ok, you use the StartCoroutine() statement to call another method, so, what I would suggest is change your LastBrick() method to.more along the lines of;

private void LastBrick() {

    if(breakableCount == 1) {    // check where you reduce the brick count in case this is zero not 1
        StartCoroutine(HandleLastBrickEvents());
    }
}

private IEnumerator HandleLastBrickEvent() {
    yield return new WaitForSeconds (5f);    // you can get the duration of the audio clip or smoke particles and use that instead of a hardcoded 5f
    Debug.Log("Smash");
}

Sorry for the delay responding, I had a meeting this morning and was sat in the car trying to type all of the above via my mobile, it wasn’t quite as easy as on the laptop so thought I’d wait until I got back so that I could check it properly on the laptop! :slight_smile:

Privacy & Terms