using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraMoveWalk : CameraManager { public float speed = 6.0f; public float gravity = 20.0f; private Vector3 moveDirection = Vector3.zero; private void Update() { if(ViewType != ViewType.Walk) return; MoveInputs(); } private void OnEnable() { character.transform.eulerAngles = lastCharacterRotate; character.enabled = true; BuildingRoom.Instance.DeactiveParents(); } public void MoveInputs() { 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); // character.transform.position = new Vector3(character.transform.position.x, 0.7f, character.transform.position.z); if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) { float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity; float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity; rotationX += mouseY * -1; rotationY += mouseX * -1; rotationX = Mathf.Clamp(rotationX, -45, 90); Vector3 nextRotation = new Vector3(rotationX, -rotationY); curentRotation = Vector3.SmoothDamp(curentRotation, nextRotation, ref smoothVelocity, smoothTime); character.transform.localEulerAngles = curentRotation; } } }