How to open doors with keypress

Hello,

I create previz-type models and animations via 3ds Max for an aviation training company. Last month, I was pushed into researching ways to develop interactive simulations for preflight maintenance training. This is when I was introduced to Unity3d. I loaded a scene with a B373 into Unity3d. In 3ds Max, I animated one of the cabin doors to open and close. In my Unity3d scene, how do I set it up so the character (first person) can walk up to the cabin door, hit the Enter key to open the door, and hit the Enter key again to close the door? I have my first person controller set up already. I am new to Unity3d and have very little scripting experience. Any thoughts would be appreciated.

Thanks,

David E.

Use the Input class to detect your key press

Use the GameObject.Find() function to get an instance of your plane

then use Animation.Play() function to play the animation you want.

The details are all in the unity documentation.

Use triggers. Set up a primitive (cube, sphere,plane,etc.) in front of the door, and one on the other side of the door. In the inspector, set their mesh in the mesh renderer to None (this will make it invisible), then click on it’s collider in the Inspector and check the IsTrigger box.

Then create a new Javascript script and add the function OnTriggerEnter(collision : Collider)
{
//Here is where you put the code that will react with the colliders. Assuming your door is tagged “door” (or some such thing), you could do this: if(collider.gameObject.tag==“door” Input.GetKeyDown(“Enter”))
{ //play the animation of your door opening }

}

attaching the script to your first person object will then make touching the trigger play the animation of your door opening. Do the same for the other side, but play the closing animation.

Thanks you guys for your replies! @MERKB I appreciate your detailed response. I used your technique and it worked perfectly!

Thank you kindly,

David E.