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);
}
}