Click and drag box not working

I have been working on a crosshair that attaches to the cell underneath the mouse cursor in an isometric game. When you click and drag to form a selection box (band-select) the cursor splits, and it works. The problem is that it only works properly when it is used in the center of the map (at 0,0). Anywhere else on the map and it’s all botched up. Here is the code:

Vector3Int cp = g_grid.LocalToCell(mouseWorldPos());
transform.localPosition = g_grid.GetCellCenterLocal(cp);

if (finalObject == st_house)
{
	if (Input.GetMouseButtonDown(0))
	{
		//drag for houses and road
		//Debug.Log(cp)
		MouseButtonPressed = true;
		Ghost_a.transform.localPosition = g_grid.GetCellCenterLocal(cp);
		Ghostpos_x = cp;
		Ghostpos_y = cp;
	}
	if (Input.GetMouseButton(0) && MouseButtonPressed == true)
	{
		Ghostpos_x.y = cp.y;
		Ghost_x.transform.localPosition = g_grid.GetCellCenterLocal(Ghostpos_x);
		
		Ghostpos_y.x = cp.x;
		Ghost_y.transform.localPosition = g_grid.GetCellCenterLocal(Ghostpos_y);
	}
}
if (finalObject != st_house || (!Input.GetMouseButton(0) && MouseButtonPressed == false))
{
	Ghost_a.transform.localPosition = g_grid.GetCellCenterLocal(cp);
	Ghost_x.transform.localPosition = g_grid.GetCellCenterLocal(cp);
	Ghost_y.transform.localPosition = g_grid.GetCellCenterLocal(cp);
}

Later in the code i have:

if (EventSystem.current.IsPointerOverGameObject() || finalObject == null)
{
	if(gameObject.GetComponent<SpriteRenderer>().enabled == true ||
	Ghost_a.GetComponent<SpriteRenderer>().enabled == true ||
	Ghost_x.GetComponent<SpriteRenderer>().enabled == true ||
	Ghost_y.GetComponent<SpriteRenderer>().enabled == true)
	{
		gameObject.GetComponent<SpriteRenderer>().enabled = false;
		Ghost_a.GetComponent<SpriteRenderer>().enabled = false;
		Ghost_x.GetComponent<SpriteRenderer>().enabled = false;
		Ghost_y.GetComponent<SpriteRenderer>().enabled = false;
	}
}
else
{
	if(gameObject.GetComponent<SpriteRenderer>().enabled == false ||
	Ghost_a.GetComponent<SpriteRenderer>().enabled == false ||
	Ghost_x.GetComponent<SpriteRenderer>().enabled == false ||
	Ghost_y.GetComponent<SpriteRenderer>().enabled == false)
	{
		gameObject.GetComponent<SpriteRenderer>().enabled = true;
		Ghost_a.GetComponent<SpriteRenderer>().enabled = true;
		Ghost_x.GetComponent<SpriteRenderer>().enabled = true;
		Ghost_y.GetComponent<SpriteRenderer>().enabled = true;
	}
	if(CursorSwitch != 0 && g_grid.GetCellCenterLocal(Ghostpos_x).x <= cp.y &&
	g_grid.GetCellCenterLocal(Ghostpos_y).y <= cp.x)
	{
		gameObject.GetComponent<SpriteRenderer>().sprite = Cursor_down;
		Ghost_a.GetComponent<SpriteRenderer>().sprite = Cursor_up;
		Ghost_x.GetComponent<SpriteRenderer>().sprite = Cursor_right;
		Ghost_y.GetComponent<SpriteRenderer>().sprite = Cursor_left;
		CursorSwitch = 0;
	}
	if(CursorSwitch != 1 && g_grid.GetCellCenterLocal(Ghostpos_x).x >= cp.y &&
	g_grid.GetCellCenterLocal(Ghostpos_y).y <= cp.x)
	{
		gameObject.GetComponent<SpriteRenderer>().sprite = Cursor_left;
		Ghost_a.GetComponent<SpriteRenderer>().sprite = Cursor_right;
		Ghost_x.GetComponent<SpriteRenderer>().sprite = Cursor_up;
		Ghost_y.GetComponent<SpriteRenderer>().sprite = Cursor_down;
		CursorSwitch = 1;
	}
	if(CursorSwitch != 2 && g_grid.GetCellCenterLocal(Ghostpos_x).x <= cp.y &&
	g_grid.GetCellCenterLocal(Ghostpos_y).y >= cp.x)
	{
		gameObject.GetComponent<SpriteRenderer>().sprite = Cursor_right;
		Ghost_a.GetComponent<SpriteRenderer>().sprite = Cursor_left;
		Ghost_x.GetComponent<SpriteRenderer>().sprite = Cursor_down;
		Ghost_y.GetComponent<SpriteRenderer>().sprite = Cursor_up;
		CursorSwitch = 2;
	}
	if(CursorSwitch != 3 && g_grid.GetCellCenterLocal(Ghostpos_x).x >= cp.y &&
	g_grid.GetCellCenterLocal(Ghostpos_y).y >= cp.x)
	{
		gameObject.GetComponent<SpriteRenderer>().sprite = Cursor_up;
		Ghost_a.GetComponent<SpriteRenderer>().sprite = Cursor_down;
		Ghost_x.GetComponent<SpriteRenderer>().sprite = Cursor_left;
		Ghost_y.GetComponent<SpriteRenderer>().sprite = Cursor_right;
		CursorSwitch = 3;
	}
}

The crosshair has four brackets which all face the middle of the box. The brackets change based on the cellposition of the cursor (cp). If it’s X is greater than the ghost that slides on the Y axis, the sprites change accordingly. Same with the cursor on the Y axis, as well as both X and Y and, of course, neither. The probolem I am having is that it seems the further away from the center it is, the corners of the box arnet angled properly to the center until you encapsulate the center of the map inside of it. In some cases, it doesnt work properly unless you expand the box to contain almost the entirity of the map. I don’t know why this doesn’t work. I assume I don’t know how LocalPosition, GetCellCentral, or LocalToCell work. What is the code actually doing and how do I fix it. I’m compleatly baffled as this seems like basic mathematics. BTW I have debug.log the Ghostpos_x, y and cp and they are all returning their respective cell positions as expected. Any help would be greatly appreciated. Thanks.

I know this an old thread, but I’ve just faced the same problem.

I created this fix:

// DISABLE INPUT DRAG SCROLL (CHROME BUG FIX)
var disableScrollDrag = false;
('input, select, textarea').unbind('mousedown').mousedown(function(e) { disableScrollDrag = true; (this).css(‘pointer-events’, ‘none’).addClass(‘disable-scroll-drag’);
});

('body').mousemove(function() { if (disableScrollDrag === true) { (‘.disable-scroll-drag’).each(function () {
$(this).css(‘pointer-events’, ‘auto’);
});
disableScrollDrag = false;
}
});
,I know this an old thread, but I’ve just faced the same problem.

I created this fix:

// DISABLE INPUT DRAG SCROLL (CHROME BUG FIX)
var disableScrollDrag = false;
('input, select, textarea').unbind('mousedown').mousedown(function(e) { disableScrollDrag = true; (this).css(‘pointer-events’, ‘none’).addClass(‘disable-scroll-drag’);
});

('body').mousemove(function() { if (disableScrollDrag === true) { (‘.disable-scroll-drag’).each(function () {
$(this).css(‘pointer-events’, ‘auto’);
});
disableScrollDrag = false;
}
});

MyPrepaidCenter