Guest User

Untitled

a guest
Jan 15th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Mirror;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class PlayerLook : NetworkBehaviour
  8. {
  9.  
  10.  
  11. [Header("References")]
  12. [SerializeField] WallRun wallRun;
  13.  
  14.  
  15.  
  16. [SerializeField] private float sensX;
  17. [SerializeField] private float sensY;
  18.  
  19.  
  20. [SerializeField] Transform cam;
  21. public Transform PlayerBody;
  22. public Transform PlayerRight;
  23. public Transform PlayerLeft;
  24.  
  25. float mouseX;
  26. float mouseY;
  27.  
  28.  
  29. float multiplier = 0.01f;
  30.  
  31. float xRotation;
  32. float yRotation;
  33.  
  34.  
  35.  
  36.  
  37.  
  38. private void Start()
  39. {
  40. if (!isLocalPlayer)
  41. {
  42. cam.GetComponent<Camera>().enabled = false;
  43. return;
  44. }
  45. Cursor.lockState = CursorLockMode.Locked;
  46. Cursor.visible = false;
  47.  
  48.  
  49.  
  50. }
  51.  
  52. private void Update()
  53. {
  54.  
  55.  
  56. if ((Input.GetKeyDown(KeyCode.Slash)))
  57. {
  58. Cursor.lockState = CursorLockMode.None;
  59. Cursor.visible = true;
  60. }
  61. else if ((Input.GetKeyUp(KeyCode.Slash)))
  62. {
  63. Cursor.lockState = CursorLockMode.Locked;
  64. Cursor.visible = false;
  65.  
  66. }
  67.  
  68. MyInput();
  69.  
  70. cam.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
  71. PlayerBody.Rotate(Vector3.up * mouseX);
  72.  
  73.  
  74. }
  75.  
  76.  
  77. void MyInput()
  78. {
  79.  
  80.  
  81. mouseX = Input.GetAxisRaw("Mouse X");
  82. mouseY = Input.GetAxisRaw("Mouse Y");
  83.  
  84. yRotation += mouseX * sensX * multiplier;
  85. xRotation -= mouseY * sensY * multiplier;
  86.  
  87. xRotation = Mathf.Clamp(xRotation, -90f, 90f);
  88.  
  89. cam.transform.rotation = Quaternion.Euler(xRotation, yRotation, wallRun.tilt);
  90. PlayerBody.Rotate(Vector3.up * mouseX);
  91. PlayerRight.Rotate(Vector3.up * mouseX);
  92. PlayerLeft.Rotate(Vector3.up * mouseX);
  93.  
  94.  
  95. }
  96. }
  97.  
  98.  
  99.  
  100.  
Advertisement
Add Comment
Please, Sign In to add comment