Untitled

                Never    
C#
       
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
[RequireComponent(typeof(Rigidbody2D))]
public class MoveComponent : MonoBehaviour
{
    [SerializeField]
    private float _speedFactor = 1f;
 
    private Camera _mainCamera = null;
    private Rigidbody2D _body = null;
 
    private Vector3 _currentDelta = Vector3.zero;
 
    private void Awake()
    {
        _mainCamera = Camera.main;
        _body = GetComponent<Rigidbody2D>();
    }
 
    private void Update()
    {
        var worldMousePointer = _mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, _mainCamera.nearClipPlane));
        worldMousePointer.z = _body.transform.position.z;
        _currentDelta = worldMousePointer - _body.transform.position;
    }
 
    private void FixedUpdate()
    {
        _body.MovePosition(_body.transform.position + (_currentDelta * Time.fixedDeltaTime * _speedFactor));
        _currentDelta = Vector3.zero;
    }
}

Raw Text