After following the excellent tutorial about sound effects & scripting, I have a good understanding of how to add collision sounds to GameObjects. However, in a “real-world” application, things are usually more complex:
For example, the sound that a baseball makes when hitting a beer can is very different from the sound it makes when hitting a wooden wall, or a grassy ground. At the same time, the sound the beer can makes when it hits another falling beer can, or a wooden table, or again the ground is also different (not to mention the differences between the can being hit laterally or at the top/bottom).
In the end, the required collision sounds would not be a simple “play this audio clip when a collision with anything is detected”, but rather a 2D matrix of “play this sound when an object of type X hits an object of type Y”. This leads to the question where we would implement the logic for that matrix? Adding it to each object sounds like a maintenance nightmare (basically a huge switch-statement selecting the sound depending on the colliding object type), and also be redundant (for example, object “Baseball” would play a sound when hitting “BeerCan”, but object “BeerCan” would also play the same sound when colliding with an object of type “Baseball”.
Another topic is how to efficiently identify the “type” of the colliding object? One (easy, but dirty) way I can think of is using tags. Another one would be to dig into the Collider object of the other object, and determine its material.
So, what I’m asking is: Are there any common ways / good practices / recommended approaches to deal with this topic? I’m thankful for any ideas or pointers to relevant documentation or tutorials.