Character not following path

Hi guys,
I’m currently working on a pathfinding. A chracter as to follow a path considering a condition. Without condition the player avoids the walls but as soon as I put a condition he doesn’t follow the path (the gizmos are still drawn).
Could you help me please ?

        var distance = Vector2.Distance(ai.position, nearestBoy.transform.position);
        if (nearestBoy.GetComponent<BoyStats>().isWanted == true)
        {
            if (distance < 0.15f)
            {
                //Caught
                nearestBoy.GetComponent<BoyStats>().isCaught = true;
                nearestBoy.GetComponent<BoyStats>().Caught();
                ai.maxSpeed = 0;
            }
            else if (distance < 3.0f)
            {   //Chase
                ai.maxSpeed = 1.5f;
                ai.destination = nearestBoy.transform.position;
                ai.SearchPath();
            }
            else if (!ai.pathPending && (ai.reachedEndOfPath || !ai.hasPath))
            {
                //Wandering
                ai.maxSpeed = 0.3f;
                ai.destination = PickRandomPoint();
                ai.SearchPath();
            }
        }

Hi

How often is the code in your first script run?