// Update is called once per frame void Update() { RaycastHit2D blocked = Physics2D.Linecast(transform.position, target.position, 1 << 8); if (!blocked) { if (nav.CheckPath(target.position)) { nav.SetDestination(target.position); } } }