Hello There;
I have a Door i want to open and close the door using the same input key.
this is my code:
var DoorStatus = false;
var Door:Transform;
var area: int=2;
function Update ()
{
var forward = (Door.transform.TransformDirection (Vector3.forward));
//target = GameObject.FindWithTag("Cube").transform;
if(Physics.Raycast(Door.transform.position, forward,area))
{
print("I am infront of the Door");
if (Input.GetKey ("e") !DoorStatus)
{
animation.CrossFade("O");
print ("Door is Open Now");
DoorStatus = true;
}
if (Input.GetKey ("e") DoorStatus)
{
animation.CrossFade("C");
print ("Door is Closed Now");
DoorStatus = false;
}
}
}
i know where is the problem, it is DoorStatus variable, since it become true in the first if statement and it goes to the second if statement to do it.
how i can fix this