- Home /
Door Sound Script Help
Hey I have some issues with the sound script for my door, so my door has a box collider with a trigger and it gets open with a mouse click. But i have this separate script for the door sound, and i guess it misses the ontriggerenter or something because it doesnt matter where I'm in the map, when I click, the door sound gets activated. I know it's probably easy to fix, but I'm not too good yet in scripting. So what i want is that the sound gets activated only if the player clicked on the trigger of the door (inside the box collider); Here is the sound script:
var shootSound:AudioClip;
function Update () { if(Input.GetKeyDown(KeyCode.Mouse0)){ audio.PlayOneShot(shootSound); } }
Answer by Visual Programmer · Sep 28, 2013 at 08:20 AM
I get what you're trying to do. Use OnMouseDown(); it's great for non-mobile point and click games.
function OnMouseDown(){
audio.PlayOneShot(shootSound);
}
I want that the sound plays when I click inside the box collider of my door(wich is a trigger), because my current script make the door sound play everywhere i click in my map, and I need it to play only when i'm inside the box collider of my door, something like this but that works, because i don't know why this doesn't:
pragma strict
var shootSound:AudioClip;
function OnTriggerEnter (other : Collider) { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.$$anonymous$$ouse0)){ audio.PlayOneShot(shootSound); } }
Do you have any suggestions?, I'm really looking forward this script, it will work when i click over different objects making different sounds (windows, drawers, buttons, etc)