Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Mirror;
- using UnityEngine.SceneManagement;
- public class PlayerLook : NetworkBehaviour
- {
- [Header("References")]
- [SerializeField] WallRun wallRun;
- [SerializeField] private float sensX;
- [SerializeField] private float sensY;
- [SerializeField] Transform cam;
- public Transform PlayerBody;
- public Transform PlayerRight;
- public Transform PlayerLeft;
- float mouseX;
- float mouseY;
- float multiplier = 0.01f;
- float xRotation;
- float yRotation;
- private void Start()
- {
- if (!isLocalPlayer)
- {
- cam.GetComponent<Camera>().enabled = false;
- return;
- }
- Cursor.lockState = CursorLockMode.Locked;
- Cursor.visible = false;
- }
- private void Update()
- {
- if ((Input.GetKeyDown(KeyCode.Slash)))
- {
- Cursor.lockState = CursorLockMode.None;
- Cursor.visible = true;
- }
- else if ((Input.GetKeyUp(KeyCode.Slash)))
- {
- Cursor.lockState = CursorLockMode.Locked;
- Cursor.visible = false;
- }
- MyInput();
- cam.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
- PlayerBody.Rotate(Vector3.up * mouseX);
- }
- void MyInput()
- {
- mouseX = Input.GetAxisRaw("Mouse X");
- mouseY = Input.GetAxisRaw("Mouse Y");
- yRotation += mouseX * sensX * multiplier;
- xRotation -= mouseY * sensY * multiplier;
- xRotation = Mathf.Clamp(xRotation, -90f, 90f);
- cam.transform.rotation = Quaternion.Euler(xRotation, yRotation, wallRun.tilt);
- PlayerBody.Rotate(Vector3.up * mouseX);
- PlayerRight.Rotate(Vector3.up * mouseX);
- PlayerLeft.Rotate(Vector3.up * mouseX);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment