예제 #1
0
    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");
        }
    }
예제 #2
0
 void Start()
 {
     activeState = flightState.HOVER;
 }