You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
867 B
32 lines
867 B
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class MouseLook : MonoBehaviour |
|
{ |
|
public float mouseSensitivity = 100f; |
|
public Transform playerBody; |
|
|
|
private float xRotation = 0f; |
|
|
|
// Start is called before the first frame update |
|
void Start() |
|
{ |
|
// Keep the mouse cursor in the game window |
|
Cursor.lockState = CursorLockMode.Locked; |
|
} |
|
|
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; |
|
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; |
|
|
|
xRotation -= mouseY; |
|
xRotation = Mathf.Clamp(xRotation, -90f, 90f); |
|
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); |
|
|
|
playerBody.Rotate(Vector3.up * mouseX); |
|
|
|
} |
|
}
|
|
|