Why 2D colliders doesn't work?

First of all apologies if there are any mistakes on my english, isn’t my first language.
I’m a very begginer in unity and I’m learning the basics right now,
I’m creating a game where the main gameObject should move to another gameObject position on mouse right click. This is the code I have:

    GameObject GetClickedGameObject()
	{
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		RaycastHit hit;
		if (Physics.Raycast(ray, out hit))
			return hit.transform.gameObject;
		else
			return null;
	}
	
	void Update () {
		GameObject clickedGmObj = null;
		if(Input.GetMouseButtonDown(0)){
			clickedGmObj = GetClickedGameObject();
			if(clickedGmObj != null)
				Debug.Log(clickedGmObj.name);
			alien.transform.position = (clickedGmObj.transform.position);
		}
	}

Everything is fine when I use 3D colliders, the object (alien) moves to the position I expected, but my game is in 2D, so I would like to use 2D colliders also in order to modify their shape, because every collider delimits one territory. The thing is when I use 2D coll. nothing happens when clicked.

Another doubt I have is that when I click somewhere where there isn’t an object, the game is paused and this message appears in the console:

NullReferenceException: Object reference not set to an instance of an object
Movimiento2.Update ()

Can I ignore it?

Thanks in advance.

First of all, your code is wrong for 2D. Your GetClickedGameObject() function has code for 3D not 2D. That’s why you are getting NullReferenceException because clickeGmobj is null and you are trying to get transform of null object. To avoid this, include
alien.transform.position = (clickedGmObj.transform.position);

In your if statement before that. For 2D, your GetClickedGameObject() function should be:

GameObject GetClickedGameObject()
    {
       Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
       RaycastHit2D hit = Physics2D.Raycast(mousePos, Vector2.zero); //use Vector2.zero only when object will be directly under camera.
       if (hit.collider) 
         return hit.transform.gameObject;
       else
         return null;
    }