Hi everyone. I was wandering if there was a way to make a sound deploy when hitting a specific object/terrain, because I really need it for a game that needs sounds, desperately.
Check the name or tag of the colliding object in OnCollisionEnter, and play an appropriate sound depending on the results:
var funkySound : AudioClip;
var enemyHitSound : AudioClip;
function OnCollisionEnter (other : Collision) {
if (other.gameObject.name == "FunkyThing") {
audio.clip = funkySound;
audio.Play();
}
else if (other.gameObject.tag == "Enemy") {
audio.clip = enemyHitSound;
audio.Play();
}
}