Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityStandardAssets.Utility;
- using Steamworks;
- using UnityStandardAssets.CrossPlatformInput;
- [RequireComponent(typeof(PlayerMotor))]
- [RequireComponent(typeof(CharacterController))]
- public class PlayerController : MonoBehaviour
- {
- [SerializeField] private CharacterController m_CharacterController;
- public bool canJump;
- [SerializeField]
- private float Walkspeed = 5f;
- [SerializeField]
- private float Runspeed = 8f;
- [SerializeField] private float JumpSpeed = 6.6f;
- [SerializeField]
- private float lookSensitivity = 3f;
- private PlayerMotor motor;
- private Camera m_Camera;
- void Start()
- {
- motor = GetComponent<PlayerMotor>();
- m_Camera = Camera.main;
- }
- void Update()
- {
- if (PauseMenu.IsOn)
- {
- if (Cursor.lockState != CursorLockMode.None)
- Cursor.lockState = CursorLockMode.None;
- motor.Move(Vector3.zero);
- motor.Rotate(Vector3.zero);
- motor.RotateCamera(0f);
- return;
- }
- if (Cursor.lockState != CursorLockMode.Locked)
- {
- Cursor.lockState = CursorLockMode.Locked;
- }
- //Calculate movement velocity as a 3D vector
- float _xMov = Input.GetAxis("Horizontal");
- float _zMov = Input.GetAxis("Vertical");
- Vector3 _movHorizontal = transform.right * _xMov;
- Vector3 _movVertical = transform.forward * _zMov;
- if (Input.GetKey(KeyCode.LeftShift))
- {
- // Final movement vector
- Vector3 _velocity = (_movHorizontal + _movVertical) * Runspeed;
- //Apply movement
- motor.Move(_velocity);
- }
- else
- {
- // Final movement vector
- Vector3 _velocity = (_movHorizontal + _movVertical) * Walkspeed;
- //Apply movement
- motor.Move(_velocity);
- }
- //Calculate rotation as a 3D vector (turning around)
- float _yRot = Input.GetAxisRaw("Mouse X");
- Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensitivity * Time.deltaTime * 30f;
- //Apply rotation
- motor.Rotate(_rotation);
- //Calculate camera rotation as a 3D vector (turning around)
- float _xRot = Input.GetAxisRaw("Mouse Y");
- float _cameraRotationX = _xRot * lookSensitivity * Time.deltaTime * 30f;
- //Apply camera rotation
- motor.RotateCamera(_cameraRotationX);
- //Get if player pressed Space and Jump
- if (Input.GetButtonDown("Jump") && canJump == true)
- {
- Vector3 jumpvel = new Vector3(0f, JumpSpeed, 0f);
- motor.Jump(jumpvel);
- motor.PlayJumpSound();
- canJump = false;
- }
- }
- private void OnCollisionEnter(Collision collision)
- {
- if (collision.transform.name == "Floor" || collision.transform.name == "Table")
- {
- Vector3 jumpvel = new Vector3(0f, 0f, 0f);
- motor.Jump(jumpvel);
- motor.PlayLandingSound();
- canJump = true;
- }
- }
- }
Add Comment
Please, Sign In to add comment