Multiple Hit Sounds and Unity 5

In my continuing quest to make things difficult for myself, I decided I wanted multiple sounds to play depending on what the ball hits. I have the following in Unity 5:

  • Ball hits paddle sound.
  • Ball hits a block and it does not break sound.
  • Ball hits a block and it is destroyed sound.

I put all the sounds on the ball. This seemed to make the most sense as the ball is always involved in the collisions. I had some fun and games trying to work out how to address each sound individually but, using some stuff we did on arrays in previous lectures, came up with the following.

It all seems to work fine. No clipping of sounds when the block is destroyed (sounds are on the ball). I had to make “timesHit” public so I could test whether or not a block was going to get destroyed or not.

I’m thinking I should probably try to play the block hit sounds by remotely triggering them from the brick rather than testing how many times the brick has been hit on both the ball and the brick … might look into that…

1 Like

Privacy & Terms