Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        float horiz = Input.GetAxis(horizontal);
        float vert  = Input.GetAxis(vertical);

        playerController.Move(horiz, vert);
        headBob.Bob(horiz, vert);

        float lX = Input.GetAxis(lookX);
        float lY = Input.GetAxis(lookY);

        bodyCam.Look(lX, lY);
        headCam.Look(lX, lY);

        if (Objective.gameOver)
        {
            // Restart game
            if (Input.GetButtonDown(jump))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            }

            // Quit game
            if (Input.GetButtonDown(cancel))
            {
                #if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
                #else
                Application.Quit();
                #endif
            }
        }

        if (Input.GetButtonDown(jump))
        {
            playerController.Jump();
        }

        if (Input.GetButtonDown(pickup))
        {
            pickupsManager.UsePickup();
        }

        if (Input.GetButtonDown(reload))
        {
            gun.Reload();
        }
        else if (Input.GetButtonDown(sprint))
        {
            RotateGunDown();
            playerController.speed = speed * 1.5f;
        }
        else if (Input.GetButton(sprint))
        {
            playerController.speed = speed * 1.5f;
        }
        else if (Input.GetButtonUp(sprint))
        {
            RotateGunUp();
            playerController.speed = speed;
            nextShoot = Time.time + sprintCooldown;
        }
        else if ((Input.GetButton(shoot) || Input.GetAxis(shoot) > 0f) && Time.time > nextShoot)
        {
            gun.Shoot();
        }
    }