Код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterController : MonoBehaviour
{
[SerializeField][Range(-3,3)] float Sensitivity;
[SerializeField] Transform Camera;
[SerializeField] CharacterController controller;
float CameraPitch;
private void Start()
{
controller = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
MouseMoving();
Moving();
}
void MouseMoving()
{
Vector2 MouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
CameraPitch -= MouseDelta.y * Sensitivity;
Mathf.Clamp(CameraPitch, -90, 90);
Camera.localEulerAngles = Vector3.right * CameraPitch;
transform.Rotate(Vector3.up * MouseDelta.x * Sensitivity);
}
private void Moving()
{
Vector2 InputDirection = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
InputDirection.Normalize();
Vector3 Velosity = transform.forward * InputDirection.y + transform.right * InputDirection.x;
controller.Move(Velosity * Time.deltaTime); // CharacterController не содержит определение Move
}
}