Вот скрипт:
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FhirdPersonCharaster2D : MonoBehaviour
{
public float speed;
Rigidbody2D rb;
public Joystick joystick;
private Vector2 moveVelocity;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
Vector2 moveInput = new Vector2(joystick.Horizontal, joystick.Vertical);
moveVelocity = moveInput.normalized * speed;
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + moveVelocity * Time.deltaTime);
}
}
using System.Collections.Generic;
using UnityEngine;
public class FhirdPersonCharaster2D : MonoBehaviour
{
public float speed;
Rigidbody2D rb;
public Joystick joystick;
private Vector2 moveVelocity;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
Vector2 moveInput = new Vector2(joystick.Horizontal, joystick.Vertical);
moveVelocity = moveInput.normalized * speed;
}
private void FixedUpdate()
{
rb.MovePosition(rb.position + moveVelocity * Time.deltaTime);
}
}