I have looked for an object dragging script for Unity 2D. I have found a good method on the internet, but it seems it\'s just working in Unity 3D. It\'s not good for me as I\'m
You're almost there.
Change the RequireComponent line in your code to:
[RequireComponent(typeof(BoxCollider2D))]
And add a BoxCollider2D component to the object to which you add your script. I just tested it and it works fine.