- Home /
Opening an animated door with a keycard
I am trying to open a door with a keycard. I have my door open/close script, but would like to add more code stating "This door will not open unless I have a card in my inventory." I need to pickup the card and be able to open the door afterwards. I have seen many tutorials on this, but none that already has already made animation on it. This is my code so far:
#pragma strict
var DoorState = false;
var InFrontOfTheDoor = false;
var Door : GameObject;
var SoundClose : GameObject;
var SoundOpen : GameObject;
function Update ()
{
if(Input.GetKeyDown(KeyCode.E) && InFrontOfTheDoor)
{
if (DoorState == false)
{
ChangeDoorStateOpen{};
}
else
{
ChangeDoorStateClosed();
}
}
}
function ChangeDoorStateOpen()
{
DoorState = true;
Door.animation.CrossFade("DoorOpen");
SoundOpen.audio.Play();
}
function ChangeDoorStateClosed()
{
DoorState = false;
Door.animation.CrossFade("DoorClose");
SoundClose.audio.Play();
}
function OnTriggerEnter()
{
InFrontOfTheDoor = true;
}
function OnTriggerExit()
{
InFrontOfTheDoor = false;
}
Comment
Your answer
Follow this Question
Related Questions
key to open gate 1 Answer
Door key scripting problem 0 Answers
Puzzle open door ? 1 Answer
How to open a door with the "E" key 1 Answer
Opening a door with a key 2 Answers