Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class TopDownMovement : MonoBehaviour
- {
- public float speed = 5f; // Скорость передвижения
- private Rigidbody2D rb;
- void Start()
- {
- rb = GetComponent<Rigidbody2D>(); // Получаем доступ к Rigidbody2D
- }
- void FixedUpdate()
- {
- // Получаем ввод по осям X и Y
- float moveX = Input.GetAxisRaw("Horizontal");
- float moveY = Input.GetAxisRaw("Vertical");
- // Создаем вектор движения
- Vector2 movement = new Vector2(moveX, moveY).normalized;
- // Двигаем персонажа
- rb.velocity = movement * speed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement