Hey all,
I recently made a script to play a sound effect when the player collides with a wall, object etc. I also have the music to play on awake but the sound effects do not work. We’ve tried onCollisionEnter, onTriggerEnter, OnControllerColliderHit, and the sound effects do not play. Any thoughts on why this is happening?
Script:
var table_hit : AudioClip;
var wall_hit : AudioClip;
var player_hit : AudioClip;
var plant_hit : AudioClip;
var proj_hit : AudioClip;
function OnControllerColliderHit(collision : Collision) {
Debug.Log(“hit from sounds”);
for(var contact : ContactPoint in collision.contacts){
Debug.DrawRay(contact.point, contact.normal, Color.white);
}
if(collision.gameObject.tag == “table”){
audio.PlayOneShot(table_hit);
}if(collision.gameObject.tag == “wall”){
Debug.Log(“hit wall”);
audio.PlayOneShot(wall_hit);
}if(collision.gameObject.tag == “plant”){
audio.PlayOneShot(plant_hit);
}if(collision.gameObject.tag == “Player”){
audio.PlayOneShot(player_hit);
}if(collision.gameObject.tag == “projectile”){
audio.PlayOneShot(proj_hit);
}
}