[code=javascript]var doorOpened:boolean=false;
var doorAudio:AudioClip;
var doorShut:AudioClip;
var timer:float=0.0;
function OnControllerColliderHit(hit:ControllerColliderHit){
if((hit.gameObject.tag=="house1")&&(doorOpened==false)){
openDoor();
}
}
function Update () {
if(doorOpened){
timer+=Time.deltaTime;
}
if(timer>=5){
shutDoor();
}
}
function shutDoor(){
var theHouse=gameObject.FindWithTag("house1");
theHouse.animation.Play("doorshuts");
doorOpened=false;
audio.PlayOneShot(doorShut);
timer=0;
}
function openDoor(){
doorOpened=true;
var theHouse=gameObject.FindWithTag("house1");
theHouse.animation.Play("dooropen");
audio.PlayOneShot(doorAudio);
}[/code]