I am making a 2d game and I want to make it where to can pick up bricks with your mouse

I am making a 2d game and I want to make it where to can pick up bricks with your mouse and move them. Thanks

That sounds like a fun game! I’m sure others would like to do the same thing.

By the way, if you don’t ask a question, you don’t get an answer.

Break it down into smaller parts,
Learn how to get if the mouse is over the brick…pisss(OnMouseOver)
Then learn to get if you click on it…pisssss(Input.GetMouseButtonDown, inside of the above).
Then learn to get the mouse position…pissss(Input.mousePosition, I think!? I’m not on pc)
Then learn to move the brick…pissss(transform.Translate)

. Next time I won’t be so kind. Don’t ask us to do your work…wait you didn’t even ask a question. :stuck_out_tongue:

I put in in a code format so it is positioned right, it’s hard to do on mobile :wink:

I guess you could call the comments here a lesson on how to ask a detailed question on Unity Answers. I have to interject as I feel OnMouse functions to be unreliable, what you should learn about is Raycast and Collider. Collider becomes a big thing in Unity, so is good to learn and understand. Raycasting returns so much information, it is harder to do things without it.

So now there are some things to start considering : colliders help identify objects and allow them to react physically; raycasts are great for detecting colliders and returning useful information about them.

Unity Scripting Reference links :

Those are probably the most confusing links to read apart from Transform and GameObject, but use the Unity Scripting Reference (API) and things get explained well there.

But to help you start, I am going to do what is normally not allowed on this 'site, show you how to put all the different pieces together to do what you want.

Start with a mouse input : Unity - Scripting API: Input : leads to > > : Unity - Scripting API: Input.GetMouseButtonDown

function Update() 
{
    if ( Input.GetMouseButtonDown(0) )
    {
        Debug.Log( "Pressed left click." );
    }
}

Now we want to select a brick, and remember that brick. For this we store a reference to it. For now you are probably just moving the brick, so we shall store the type that is Transform.

var selectedBrick : Transform // a variable that is typecast to Transform to store the selected (chosen) brick

now for the fun part, to use raycast to find the brick that is clicked then store a reference to it ! You have the raycast link above. Scroll down to the very last example :

var ray = Camera.main.ScreenPointToRay( Input.mousePosition ); // from the camera in a direction based on mouse screen position
var hit : RaycastHit; // special variable type that returns information from colliders that were raycast
if ( Physics.Raycast( ray, hit, 100 ) ) // if ( a ray in the input direction, with the ray hit information to return, for a distane of 100 units from the origin )
{
    Debug.DrawLine( ray.origin, hit.point ); // show a line from the start to where the ray first hit some collider
	
	Debug.Log( "ray hit (name) : " + hit.collider.gameObject.name ); // the name of the gameObject of the collider that was hit
	Debug.Log( "ray hit (tag) : " + hit.collider.gameObject.tag ); // you can find out lots about the object based on its components
}

Some interesting things here that come from one small raycast script. The links :

So put that raycast after a mouse input and it looks like this :

var selectedBrick : Transform // a variable that is typecast to Transform to store the selected (chosen) brick

function Update() 
{
    if ( Input.GetMouseButtonDown(0) )
	{
        Debug.Log( "Pressed left click." );
		
		var ray = Camera.main.ScreenPointToRay( Input.mousePosition ); // from the camera in a direction based on mouse screen position
		var hit : RaycastHit; // special variable type that returns information from colliders that were raycast
		
		if ( Physics.Raycast( ray, hit, 100 ) ) // if ( a ray in the input direction, with the ray hit information to return, for a distane of 100 units from the origin )
		{
			Debug.Log( "ray hit (name) : " + hit.collider.transform.name ); // the name of the gameObject of the collider that was hit
			
			// Store a reference to that brick
			selectedBrick = hit.collider.transform;
		}
	}
}

So really I havn’t written your script, Unity has! When you get better at raycasts you can look at Layers and LayerMask , just type them into the search box at the top-left of any Unity Scripting Reference link on this answer. Now this is only half an answer but alot to think about and get started.

If you edit your question to include what you have tried so far, and provide code you are using, then you will have a better chance for better answers.

Definitely watch the unity3Dstudent series. Start at the bottom and work up : Unity 3D Student - 3d Modelling