using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
//Obliga a que quien tenga la script agregada como componente requiera un rigidbody 2D (en este caso)
[RequireComponent(typeof(Rigidbody2D))]
public class PlayerController : MonoBehaviour
{
Rigidbody2D rb;
public float speed;
private float movementX;
private float movementY;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void OnMove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.x;
movementY = movementVector.y;
}
private void FixedUpdate()
{
rb.velocity = new Vector2(movementX, movementY) * speed;
}
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?