Airlock Door Code Problems [Solved]

var anim : String;
var AnimationSource = gameObject;

function OnTriggerStay()

 { 

if(Input.GetKeyDown(KeyCode.E))
animation.Play("AirlockOpen", PlayMode.StopAll);
}

Ok so this is my code. It works so far.
Now i want 2 things.


1.) When my player enters the trigger zone i want to display a message (or even better a image) somewhere in the bottom center of the screen. Something like “Open/Close [E]”. A picture would be better because i can stylize it more than a font.


2.) Somehow i have to check if the door is open. Maybe by setting a var when i play the animation to open and by setting it again when i play the animation to close. So my script know when to close by pressing “E” and when to open. Right now i have only one animation that opens the door. Do i need one to close it aswell or can i just play the “Open-animation” backwards?


I know i already had a topic for that code but for a different problem so i wasnt sure if i should post a new Q or use the old one.

Anyway, help is much appreciated, thanks.

PS: I’m from Austria so my English isn’t the best.

Ok i solved it. This is the working code for anyone who needs it. I hope i explained everything in the code. Its JavaScript btw. Thanks to everyone who helped me.


var AnimationSource = gameObject;//Source of the animations used in the Script
var inside : boolean = false;//var that stores inside or outside of trigger // Used for Open/Close Hint
var image : Texture2D;//Texture of Open/Close Hint
var open : boolean = false;//var that stores Open/Close state of door
//----------------------------------------------------------------------
function OnTriggerEnter (col : Collider) //Displaying the Open/Close Hint
	{

		if(col.gameObject.name == "First Person Controller")//PlayerName
		{inside = true;}
	}
//---------------------------------------------------------------------
function OnTriggerStay (col : Collider) 
{

	if(col.gameObject.name == "First Person Controller")//PlayerName

		{
			if 		(Input.GetKeyDown(KeyCode.E)&& open == false && !animation.IsPlaying("AirlockClose"))//Closing the Airlock //Making sure that no other animation is playing
					{
					open = true;
					animation.Play("AirlockOpen", PlayMode.StopAll);
					}
				
		else if		(Input.GetKeyDown(KeyCode.E)&& open == true && !animation.IsPlaying("AirlockOpen"))//Closing the Airlock //Making sure that no other animation is playing
					{
					open = false;
					animation.Play("AirlockClose", PlayMode.StopAll);
					}
		}
}
//-------------------------------------------------------------------------

	function OnTriggerExit (col : Collider) //removing Open/Close Hint
		{

			if(col.gameObject.name == "First Person Controller")//PlayerName
			{inside = false;}
		}
//-------------------------------------------------------------------------
    
 
function OnGUI()//hint for opening/closing 
	{
		if (inside == true)
			{
			GUI.Label(Rect(Screen.width/2-128,Screen.height-Screen.height/3,256,64), image);
			}
	}

Hello my friend!
1: You could use a Boolean variable when you stay inside the collider and turn it on and off. When its on you will use a GUI Box to show your image. For example:

var inside : boolean = false;

var image : Texture2D;

function OnTriggerStay (col : Collider) //Using col and collider you can make it work ONLY for the door and not for any other triggers. Col will store the object hit.
{
if(col.gameObject.name == "NAME_OF_COLLIDER")
{
inside = true;

if (Input.GetKeyDown("e"))
{
animation.Play("AirlockOpen", PlayMode.StopAll);
}
}
}

function OnGUI()
{
if (inside == true)
{//Rect = posx,posy,width,height
GUI.Box(Rect(0,0,64,64), image);
}
}

2: I don’t think there is a way to reverse animations in Unity. But if you find something I would love to know! You can either:
a) Use an external modelling / animating product to reverse the animation
b) Code the door rotating
c) Make another animation

I hope this helps! P.s. sorry the script is not formatted properly I can’t make it work haha