forked from Syntax-Error/ArenaShooter
23 lines
No EOL
779 B
C#
23 lines
No EOL
779 B
C#
using UnityEngine;
|
|
|
|
public class MouseMovement : MonoBehaviour {
|
|
public float mouseSensitivity = 100f;
|
|
public Transform playerBody;
|
|
public Transform gun;
|
|
float xRotation = 0f;
|
|
// Start is called before the first frame update
|
|
private void Start() {
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void Update() {
|
|
var mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
|
|
var 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);
|
|
}
|
|
} |