Пример #1
0
    //Take values from input class and turn them into calls
    void Update()
    {
        bool isShiftHeld = (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift));

        if (isShiftHeld)
        {
            playerController.moveSpeed = walkingSpeed;
        }
        if (playerController.moveSpeed != normalSpeed && !isShiftHeld)
        {
            playerController.moveSpeed = normalSpeed;
        }

        //Force player to move via the axis
        playerController.Move(playerInput.inputAxis);

        //Apply if availible
        if (headBobber != null)
        {
            headBobber.Bob(playerController);
        }
        else
        {
            Debug.LogWarning("No head bob script on camera");
        }

        //Apply mouse look
        if (mouseLook != null)
        {
            Vector3 rotation = mouseLook.look(playerInput.mousePos);

            //Actually rotate the player and camera
            mouseLook.transform.rotation        = Quaternion.Euler(new Vector3(rotation.x, rotation.y, mouseLook.transform.rotation.eulerAngles.z));
            playerController.transform.rotation = Quaternion.Euler(new Vector3(playerController.transform.rotation.x, rotation.y, playerController.transform.rotation.eulerAngles.z));
        }
        else
        {
            Debug.LogWarning("No mouselook script found");
        }

        //This is handled by player input
        if (gunManager.currentlyEquipt != null)
        {
            if (Input.GetMouseButton(0))
            {
                gunManager.currentlyEquipt.AttackHeld();
            }
            if (Input.GetMouseButtonUp(0))
            {
                gunManager.currentlyEquipt.AttackReleased();
            }
        }
        else
        {
            Debug.LogWarning("No gun is equipt to the player");
        }
    }
Пример #2
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();
        }
    }