title: how to detect which gameobject is clicked
body: <p>I want to know which gameobject is clicked with mouse on a 2D project</p>
  
  <p>I used </p>
  
  <pre><code> void Update()
      {
          if (Input.GetMouseButtonDown(0))
          {
              clickTime = DateTime.Now;
              mousePosition = Input.mousePosition;
  
              Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
              RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
  
              if (hit != null &amp;&amp; hit.collider != null)
              {
  
  
              }
  
          }
  }
  
  </code></pre>
  
  <p>but it never goes in the second if condition</p>
  
  <p>EDIT: I am working on a single script and access all gameobject from there using GameObject.FindGameObjectWithTag() and as I understand thats why the collider code in main script doesnt triggered.
  I added a screenshot my code is in GameObject
  <a href="https://i.stack.imgur.com/Jv3ua.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jv3ua.png" alt="enter image description here"></a></p>