Dragging objects with mouse in 2D

I’m having some trouble with direction.

I’m looking to make a script that will allow me to drag certain objects on the Y and X axis when the cursor is held over the object and the left mouse button is pressed, the game is a 2D platformer.

I got this far by myself and i’m now unsure of where to go.

function Update ()
{
	if (Input.GetButton ("Fire1"))
	{
		
	}
}

I did search a little but everything i found was a little bit confusing.

Check out the OnMouseOver, OnMouseDrag, and OnMouseDown functions in the Monobehaviour class. I think this is exactly what you want. :slight_smile:

If you want more control over the process, cast a ray from the camera into the screen, with the Camera.ScreenPointToRay function.

Thanks for the reply, i’ll check all of those out tomorrow and will hopefully be able to figure something out :slight_smile: