problem with script

hi
im doing a game where is posibble to enter a car. i made my own script that enables car controller script in car object. but there is a problem: when i click “e” nothing happens.

#pragma strict
 var Car : GameObject;
 var player : GameObject;
 var door : Transform;
 var PlayerCamera : Camera;
 var CarCamera : Camera;
 var toggle : boolean;



function Start () {}
function Update () {
toggle = false;
if (Input.GetKeyDown(KeyCode.E) && toggle == false) {
toggle = true;
(GameObject.Find(Car.transform.name).GetComponent("Car_Controller") as MonoBehaviour).enabled = true;
PlayerCamera.enabled = false;
CarCamera.enabled = true;
}

if (Input.GetKeyDown(KeyCode.E) && toggle == true) {
toggle = false;
(GameObject.Find(Car.transform.name).GetComponent("Car_Controller") as MonoBehaviour).enabled = false;
PlayerCamera.enabled = true;
CarCamera.enabled = false;
player.transform.position = door.transform.position;
}

}

Because the two conditions may be validated in the same frame :

Supposing you are pressing the E key in a frame :

  1. Line 13 : toggle = false
  2. Line 14 : SInce toggle == false, you enter the condition
  3. You make some actions
  4. Line 15 : toggle = true
  5. Line 21 : Since toggle = true, you enter the condition
  6. You make the inverse of the actions done in the first condition

Conclusion : Add a “else if” line 21