title: Raycast doesn't detect hitting object unity C# 2d
body: <p>Quite new to Unity and I've been playing around with Raycasting the past few days. I have run into this problem where  the line that the raycast is meant to represent is not detecting that this has happened. So when the Raycast line hit the object I want it to simply display HIT onto the console to show that this is working. I have a feeling that the reason it isn't working is due to the fact that the line I'm seeing through debug and the line that is actually being used different. </p>
  
  <p>The code is:</p>
  
  <pre><code>void rayCast()
      {
          if (player.transform.position.x &lt;= enemy.transform.position.x)
          {
              RaycastHit2D hitLeft = Physics2D.Raycast(transform.position, -transform.right, rayDistance, 1 &lt;&lt; LayerMask.NameToLayer("Player"));
              Vector3 left = transform.TransformDirection(Vector3.left);
              Debug.DrawRay(transform.position, left * rayDistance, Color.green);
  
              if (hitLeft.collider != null)
              {
                  Debug.Log("Player is within range");
              }
              else
              {
                  Debug.Log("out of range");
              }
          }
  
  
          if (player.transform.position.x &gt;= enemy.transform.position.x)
          {
              RaycastHit2D hitRight = Physics2D.Raycast(transform.position, transform.right, rayDistance, 1 &lt;&lt; LayerMask.NameToLayer("Player"));
              Vector3 right = transform.TransformDirection(Vector3.right);
              Debug.DrawRay(transform.position, right * rayDistance, Color.green);
  
              if (hitRight.collider != null)
              {
                  Debug.Log("Player is within range");
              }
              else
              {
                  Debug.Log("out of range");
              }
          }
      }
  </code></pre>
  
  <p>Thank you in advance for any help.</p>