yet another door

I have multiples of the same door and I would like to have the user open a door and keep the door open until the user close it manually again by pressing a key. The doors can only be opened via proximity and by pressing a key. However the problem lies in figuring out the logic so that the script stores a boolean varaible in the door or in proximity. I have tried to figure this ourt for several days now I can’t get past this block. Please help.

My triggers script looks like this:

var Door : GameObject;
var  door_open : boolean = false;
static var  door_boolean = null;
static var  door_proximity : boolean = false;
static var the_door = null ;

function OnTriggerEnter() { 
	door_proximity = true;
	the_door = Door;
	door_boolean = door_open;
	print (door_boolean);
	//print (door_proximity);
}

and my player script looks like this:

function Update () {
  //print (door_trigger.door_boolean);
//print (door_trigger.door_proximity);
  if (door_trigger.door_boolean == false) {

		if (Input.GetKeyDown (KeyCode.Tab)  (door_trigger.door_proximity == true)) {
			
			door_trigger.the_door.animation.Play("doorOpen");
			door_trigger.door_boolean = true;

		}
    }
	else if (door_trigger.door_boolean) {
	
		if (Input.GetKeyDown (KeyCode.Tab)  (door_trigger.door_proximity == true)) {


			door_trigger.the_door.animation.Play("doorClose");
			door_trigger.door_boolean = false;
			audio.PlayOneShot(hitClip);
		}
	}
	
}

thank you very much in advance

I put this together awhile back, it may help you out.

http://raidensgameplace.synthasite.com/rgpimages.php

-Raiden

hey thanks for the example Raiden… that didn’t really work for my door solution, but will work for picking items in a game :smile:. Never-the-less I did figure out the door that works on a trigger. Your code did help me simplify it to one script and condense my code logic.

var Door : GameObject;
var door_open : AudioClip;
var door_shut : AudioClip;
private var  door_closed : boolean = true;
private var  door_proximity : boolean = false;
private var the_door = null ;


function OnTriggerEnter() 
{ 
	door_proximity = true;
	the_door = Door;
} 

function  OnTriggerExit()
{
	door_proximity = false;
	the_door = null;
}

function Update()
{
	if (door_proximity == true)
	{	
		if (Input.GetKeyDown (KeyCode.Tab)  ) 
			{
			if (door_closed == true) 
				{
				the_door.animation.Play("doorOpen");
				door_closed= false;
				audio.PlayOneShot(door_open);				
				}
			else
				{
				the_door.animation.Play("doorClose");
				door_closed = true;
				audio.PlayOneShot(door_shut);
				}
			}
	}
}