I Have This .js Script How To Add A Door Opening And Closing Sound

var door: Transform;
var angleOpen: int;
var angleClose: int;
var speedOpen: int = 1000;

function OnTriggerStay(other:Collider){
if (door.transform.localEulerAngles.y < angleOpen){
door.transform.Rotate(Vector3.upTime.deltaTimespeedOpen);
}
}

To the Both of you FORMAT YOUR CODE Step 1 : read this page : http://answers.unity3d.com/page/newuser.html Please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window. Watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

–

1 Answer

1

I’m a little unsure as to what you are asking…how do you add it?

I’ll assume that’s what you are looking for. In that case, you need to add the sounds to the objects as components, (drag them onto the game object), and tell the program when to play them. Remember to uncheck “play on awake”, that always trips me up with new sounds.

So then, we’ll use “door_open” and “door_close” as the sounds.

function OnTriggerStay(other : Collider){
    
    if (door.transform.localEulerAngles.y < angleOpen){
    
    door.transform.Rotate(Vector3.up*Time.deltaTime*speedOpen);
    audio.PlayOneShot(Door_open);
    }

`
This should let the sound play when you are opening the door.

It Won't Work.It Say BCE0044:expecting},found".

–

My apologies, stupid mistake. function OnTriggerStay(other : Collider){ if (door.transform.localEulerAngles.y < angleOpen){ door.transform.Rotate(Vector3.upTime.deltaTimespeedOpen); audio.PlayOneShot(Door_open); } }

–

Just as an FYI, figure I might as well, if you get an error that says 'expecting }' or 'expecting EOF', look at the formatting. You may have forgotten a bracket or have one spare.

–