using System.Collections; using System.Collections.Generic; using UnityEngine; public class MoveCharacter : MonoBehaviour { public float speed = 6.0f; public float gravity = 20.0f; private Vector3 moveDirection = Vector3.zero; private CharacterController character; void Start() { character = GetComponent(); } void Update() { if (character.isGrounded) { // Получаем движение по осям X и Z float moveDirectionY = moveDirection.y; moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; moveDirection.y = moveDirectionY; } // Применяем гравитацию moveDirection.y -= gravity * Time.deltaTime; // Двигаем персонажа character.Move(moveDirection * Time.deltaTime); } }