Как сделать своего персонажа в Unity с нуля!
В этом видео я покажу как сделать своего персонажа в Unity 2019 и более новой версии Unity. Вот код для персонажа, и не забывайте сделать Actions Map! using UnityEngine; [RequireComponent(typeof(CharacterController))] public class Player : MonoBehaviour { [Header("Параметры")] public float speed = 5f; public float runSpeed = 9f; public float sensitivity = 1f; [Header("Объекты")] public Transform player; public Transform cameraHolder; private PlayerInputMap playerInput; private Vector2 moveInput, lookInput; private CharacterController controller; [Header("Камера")] private float cameraRotationX = 0f; public float maxLookX = 80f; public float minLookX = -80f; void Start() { controller = GetComponent(); playerInput = new PlayerInputMap(); playerInput.Enable(); Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; playerInput.Player.Move.performed += ctx =﹥ moveInput = ctx.ReadValue(); playerInput.Player.Move.canceled += ctx =﹥ moveInput = Vector2.zero; playerInput.Player.Look.performed += ctx =﹥ lookInput = ctx.ReadValue(); playerInput.Player.Look.canceled += ctx =﹥ lookInput = Vector2.zero; } void FixedUpdate() { float finalSpeed = playerInput.Player.Run.IsPressed() ? runSpeed : speed; controller.Move(new Vector3(moveInput.x, 0, moveInput.y) * finalSpeed * Time.fixedDeltaTime); } void LateUpdate() { Look(); } void Look() { float x = lookInput.x; float y = lookInput.y; player.Rotate(new Vector3(0, x, 0) * sensitivity); cameraRotationX -= y * sensitivity; cameraRotationX = Mathf.Clamp(cameraRotationX, minLookX, maxLookX); cameraHolder.localRotation = Quaternion.Euler(cameraRotationX, 0, 0); } }