30 lines
834 B
C#
30 lines
834 B
C#
using UnityEngine;
|
|
|
|
public class MouseLook : MonoBehaviour
|
|
{
|
|
public float mouseSensitivity = 100f;
|
|
|
|
float xRotation = 0f; // untuk batasi rotasi vertikal
|
|
|
|
void Start()
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked; // supaya kursor hilang dan mouse terkunci di tengah layar
|
|
}
|
|
|
|
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); // supaya gak muter 360 vertikal
|
|
|
|
// rotasi vertikal kamera (pitch)
|
|
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
|
|
|
|
// rotasi horizontal player (yaw)
|
|
transform.parent.Rotate(Vector3.up * mouseX);
|
|
}
|
|
}
|
|
|