void Flap() { if (Input.GetKeyDown (KeyCode.UpArrow)) { flapTimer = 0; } if (Input.GetKey (KeyCode.UpArrow)) { activeState = flightState.RISE; } else { activeState = flightState.HOVER; } if (flapTimer > 0) { flapTimer--; } // constant flapping if (flapTimer == 0) { switch (activeState) { case flightState.HOVER: if (Input.GetKey (KeyCode.LeftArrow)) { GetComponent<Rigidbody2D> ().transform.Translate(-moveSpeed, 0, 0, Space.World); } else if (Input.GetKey (KeyCode.RightArrow)) { GetComponent<Rigidbody2D> ().transform.Translate(moveSpeed, 0, 0, Space.World); } else if (Input.GetKey (KeyCode.DownArrow)) { GetComponent<Rigidbody2D> ().transform.Translate(0, -moveSpeed/2, 0, Space.World); } break; case flightState.RISE: GetComponent<Rigidbody2D> ().AddForce (transform.up * flapForce); flapTimer = flapCooldown; break; } print ("FLAP"); } }
void Start() { activeState = flightState.HOVER; }