Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { private float moveInput; private bool facingRight = true; public FixedTouchField touchField; public Joystick joystick; [SerializeField] private int jump; [SerializeField] private int jumpCount; [SerializeField] private int jumpCountMax; Rigidbody rb; float xMov; float zMov; float yRot; public int speed = 5; private void Start() { rb = GetComponent<Rigidbody>(); } private void FixedUpdate() { xMov = joystick.Horizontal(); zMov = joystick.Vertical(); yRot = touchField.TouchDist.x / 20; Vector3 MovHor = transform.right * xMov; Vector3 MovVer = transform.forward * zMov; Vector3 velocity = (MovHor + MovVer).normalized * speed; Vector3 rotation = new Vector3(0, yRot, 0) * speed; rb.MovePosition(rb.position + velocity * Time.deltaTime); rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation)); } public void Jump() { if (jumpCount < jumpCountMax) { rb.AddForce(transform.up * jump, ForceMode.Impulse); jumpCount++; } } private void OnTriggerStay(Collider other) { if (other.tag == "ground") jumpCount = 0; } }