But allow me to optimize this a little bit more. No calling GetComponent() and not creating a new vector instance every frame, as well as using Time.deltaTime to make the movement independent from the framerate:
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Movement : MonoBehaviour
{
public float speed = 10;
private Rigidbody2D rb;
private Vector2 movementVector;
void Start()
{
rb = GetComponent<Rigidbody2D>();
movementVector = Vector2.zero;
}
void Update()
{
movementVector.x = Input.GetAxis("Horizontal");
movementVector.y = Input.GetAxis("Vertical");
rb.velocity = movementVector * speed * Time.deltaTime;
}
}