using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float speed = 5.0f;
public float lookSpeed = 2.0f;
public float jumpForce = 10.0f;
public Transform groundCheck;
public LayerMask groundMask;
private CharacterController controller;
private Vector3 moveDirection;
private bool isGrounded;
private float rotationX = 0;
void Start()
{
controller = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
#region MouseLook
isGrounded = Physics.CheckSphere(groundCheck.position, 0.2f, groundMask);
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 move = transform.right * horizontalInput + transform.forward * verticalInput;
controller.Move(move * speed * Time.deltaTime);
float mouseX = Input.GetAxis("Mouse X") * lookSpeed;
float mouseY = Input.GetAxis("Mouse Y") * lookSpeed;
// Yatay dönüş
transform.Rotate(Vector3.up * mouseX);
// Dikey dönüş
rotationX -= mouseY;
rotationX = Mathf.Clamp(rotationX, -90f, 90f); // Dikey dönüşü sınırla
transform.localRotation = Quaternion.Euler(rotationX, transform.localEulerAngles.y, 0f);
#endregion MouseLook
if (Input.GetButtonDown("Jump") && isGrounded)
{
moveDirection.y = jumpForce;
}
// Yer çekimi uygula
moveDirection.y += Physics.gravity.y * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}