Ejemplo n.º 1
0
    void FixedUpdate()
    {
        float mouseXMovement = Input.GetAxis("Mouse X");
        float mouseYMovement = Input.GetAxis("Mouse Y");
        float tankMovement   = Input.GetAxis("Horizontal");
        float bodyMovement   = Input.GetAxis("Vertical");

        body.Turn(tankMovement);
        turret.Turn(mouseXMovement);
        MoveTank(bodyMovement);
        cannon.Turn(mouseYMovement);



        if (Input.GetButton("Fire1") && cannonTimer >= cannonFireRate && cannon.CanFire())
        {
            cannonTimer = 0f;
            cannon.Fire();
        }

        if (Input.GetButtonDown("Fire2") && gun.currentState != FireMode.Auto)
        {
            gun.Fire();
        }
        else if (Input.GetButton("Fire2") && !isGunShooting && gun.currentState == FireMode.Auto)
        {
            isGunShooting = true;
            gun.Auto();
        }
        else if (Input.GetButtonUp("Fire2") && isGunShooting && gun.currentState == FireMode.Auto)
        {
            isGunShooting = false;
            gun.StopFire();
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            gun.ChangeState();
            gun.StopFire();
            isGunShooting = false;
        }
    }