Linecast is always blocked.

I’m trying to detect if there is any 2d collider obstacle (such as wall) between the player and the enemy.

I’m trying to use this script

if (Physics2D.Linecast (new Vector2 (transform.position.x, transform.position.y), new Vector2 (target.position.x, target.position.y)))
        {
                Debug.Log("There is something in the way");
        }

I’m not sure why it’s not working. Even if there is no 2d collider between the player and the enemy, the script still outputs to the console.

I don’t know if it works for your problem but I use this for raycast so that the raycast wont hit the Collider on the same gameobject

Physics2D.queriesStartInColliders = false;

That Physics2D.Linecast() call always returns a RaycastHit2D struct, isn’t it?