Mouse plane does not detect height

the basic check nearly everyone does for raycasting mouse clicks is something like this:

if (Input.GetMouseButton(1))
        {
            Plane plane = new Plane(Vector3.up, transform.position);
            rayToMouse = Camera.main.ScreenPointToRay(Input.mousePosition);
            float dist;
            plane.Raycast(rayToMouse, out dist);
            Vector3 targetPos = rayToMouse.GetPoint(dist);
            if (Physics.Raycast(rayToMouse, out hitTag, layerMask))
            {
                //if (hitTag.transform.name != "" || hitTag.transform.gameObject.layer == 9)//9 = Ground Layer
                //{
                    MarkerGO.transform.position = new Vector3(targetPos.x, targetPos.y - 1, targetPos.z);
                //}
                MovePlayerToDestination();
            }
        }

However in my case I need it to detect height here is a screenshot of the issue. The marker goes under the higher up walkable building even with a layermask…I think the main issue is there is no way to get a layermask for the plane. I can’t figure out a way to get the plane to move up when the mouse is on a higher point.54520-untitled.jpg

Check if the brown object is in the layerMask and have a mesh collider, for test use layerMask = -1 (everything).

Try this:

if (Input.GetMouseButton(1))
{
    Plane plane = new Plane(Vector3.up, transform.position);
    rayToMouse = Camera.main.ScreenPointToRay(Input.mousePosition);
    // you do not need this ! becouse hitTag is a RaycastHit and gives you this info
    // float dist;
    // plane.Raycast(rayToMouse, out dist);
    // Vector3 targetPos = rayToMouse.GetPoint(dist);
    if (Physics.Raycast(rayToMouse, out hitTag, layerMask))
    {
        Vector3 targetPos = hitTag.point; // The impact point in world space where the ray hit the collider.
        //if (hitTag.transform.name != "" || hitTag.transform.gameObject.layer == 9)//9 = Ground Layer
        //{
        MarkerGO.transform.position = new Vector3(targetPos.x, targetPos.y - 1, targetPos.z);
        //}
        MovePlayerToDestination();
    }
}