GelişmişFPSKontrolcüTak-Çalıştır .cs
C#
using UnityEngine;
public class AdvancedFPSController : MonoBehaviour
{
[Header("Ayarlar")]
public float walkSpeed = 6f;
public float sprintSpeed = 10f;
public float jumpForce = 5f;
public float sensitivity = 2f;
private CharacterController _controller;
private Camera _cam;
private float _xRot;
void Start()
{
_controller = GetComponent<CharacterController>();
_cam = GetComponentInChildren<Camera>();
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
// Mouse Look
float x = Input.GetAxis("Mouse X") * sensitivity;
float y = Input.GetAxis("Mouse Y") * sensitivity;
_xRot -= y;
_xRot = Mathf.Clamp(_xRot, -90f, 90f);
_cam.transform.localRotation = Quaternion.Euler(_xRot, 0f, 0f);
transform.Rotate(Vector3.up * x);
// Movement
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
float speed = Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : walkSpeed;
Vector3 move = transform.right * moveX + transform.forward * moveZ;
_controller.Move(move * speed * Time.deltaTime);
}
}