Pro_Unit

FPSMouseController

May 10th, 2020
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class FPSMouseController : MonoBehaviour
  4. {
  5.     [SerializeField] private float _horizontalSpeedMultuplayer = 1;
  6.     [SerializeField] private float _verticalSpeedMultuplayer = 1;
  7.     private float _horizontalAngle;
  8.     private float _verticalAngle;
  9.     private void LateUpdate()
  10.     {
  11.         var x = Input.GetAxis("Mouse X");
  12.         var y = Input.GetAxis("Mouse Y");
  13.  
  14.         _horizontalAngle += x * _horizontalSpeedMultuplayer;
  15.  
  16.         _verticalAngle -= y * _verticalSpeedMultuplayer;
  17.  
  18.         Quaternion horizontalRotation = Quaternion.AngleAxis(_horizontalAngle, Vector3.up);
  19.         Quaternion verticalRotation = Quaternion.AngleAxis(_verticalAngle, Vector3.right);
  20.  
  21.         transform.rotation = horizontalRotation * verticalRotation;
  22.  
  23.     }
  24.  
  25. }
Add Comment
Please, Sign In to add comment