mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-30 12:37:08 +01:00
Base Rigidbody Movement + FPS counter
This commit is contained in:
31
Assets/Scripts/Character/MouseLook.cs
Normal file
31
Assets/Scripts/Character/MouseLook.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MouseLook : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float mouseSensitivityX = 800f;
|
||||
[SerializeField] private float mouseSensitivityY = 700f;
|
||||
[SerializeField] private Transform playerBody; //Transform of "First Person Player" Object
|
||||
|
||||
private float xRotation = 0f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;//Lock Cursor in the center
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//Input.GetAxis is based on the Unity Input settings (edit -> Project Settings -> Input Manager)
|
||||
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivityX * Time.deltaTime;
|
||||
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivityY * Time.deltaTime;
|
||||
|
||||
xRotation -= mouseY;
|
||||
xRotation = Mathf.Clamp(xRotation, -90f, 90f); //Kopf darf sich nicht <20>berschlagen
|
||||
|
||||
|
||||
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);//Y Achse rotieren; Quaternion ist f<>r rotation
|
||||
playerBody.Rotate(Vector3.up * mouseX); //X Achse Rotieren
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user