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.