Can you fix my code? (Audio for doors)

Hello, as you know I have really poor skills in JavaScripting and such, although I have learned several things, but this I have spent hours on… I’m basically trying to make it play an open sound, when the OPEN animation begins, and the same for the CLOSE animation. All I simply want is two sound variables which I have done and want them to play when the doors do their job.

Please let me know if you can solve this code. Thank you.

#pragma strict

var doorObj:GameObject;
var isOpen = false;
var delay : float = 0.3;
var openSound : AudioClip;
var closeSound : AudioClip;


function OnMouseDown(){
   Debug.Log("Mouse is down");
      
   if(!this.isOpen){
       doorObj.animation.Play("NewOpen");
       this.isOpen = true;
       if (openSound)
        audio.PlayOneShot(openSound);
           
      }else{
         doorObj.animation.Play("NewClose");
         this.isOpen = false;
         if (closeSound)
        audio.PlayOneShot(closeSound);
      }
}
      
      function Start() {
      }
      function Update() {
      }

This should work, personally I’ve never used ‘this’ in any of my scripting so I’m not sure what it does but this will defiantly work if its attached to the door with animations on it.

var doorObj : GameObject;
var isOpen = false;
var delay = 0.3;
var openSound : AudioClip;
var closeSound : AudioClip;
 
 
function OnMouseDown(){
   Debug.Log("Mouse is down");
 
   if(!isOpen){
       animation.Play("NewOpen");
       isOpen = true;
       audio.PlayOneShot(openSound);
 
     }else{
        animation.Play("NewClose");
        isOpen = false;
        audio.PlayOneShot(closeSound);
     }
}

Also you can’t ask if(“AudioClip”), unless you were trying to see if its null (vars filled in) just put if(“Variable” == null){ then if you don’t have an audio clip in it, it won’t turn up as a error, or if your seeing if it’s playing put if(audio.isPlaying){.

From the screenshots it looks like you are missing the AudioSource component on those doors.