using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterController : MonoBehaviour
{
public float moveSpeed = 5.0f;
private UnityEngine.CharacterController controller; // Исправлено: тип CharacterController из Unity
private Vector3 moveDirection; // Добавили поле для направления движения
private void Start()
{
controller = GetComponent<UnityEngine.CharacterController>(); // Исправлено: тип CharacterController из Unity
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 moveDirection = transform.forward * verticalInput + transform.right * horizontalInput;
moveDirection.y -= 9.81f * Time.deltaTime;
controller.Move(moveDirection * moveSpeed * Time.deltaTime);
}
}
«CharaterController»
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharaterController : MonoBehaviour
{
public float moveSpeed = 5.0f;
private CharaterController controller;
private void Start()
{
controller = GetComponent<CharaterController>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 moveDirection = transform.forward * verticalInput + transform.right * horizontalInput;
moveDirection.y -= 9.81f * Time.deltaTime;
controller.Move(motion:moveDirection * moveSpeed * Time.deltaTime);
}
}
вот весь код