I need to show a highlighted area on a grid. The grid is just a grid object assigned to a gameobject and represented with shader graph material to visualize grids. The grid part can be ignored for this problem.
Now to mimic highlighting, I am using a quad since its size scales to exact 1 unit. But I am unsure how to set its position correctly as it is showing some offset. I want to start the quads top left corner to start from mouse start position as normal selection box does. Here is the code:
private void ResizeSelectionBox()
{
//controlledVisualization is the quad assigned;
Vector3 StartMousePosition = ...;
float width = Input.mousePosition.x - StartMousePosition.x;
float height = Input.mousePosition.y - StartMousePosition.y;
// Calculate the actual width and height based on the positions
float actualWidth = Mathf.Abs(width);
float actualHeight = Mathf.Abs(height);
// Set the transform's position and scale of the quad
controlledVisualization.transform.position = StartMousePosition / quadSizeUnit;
controlledVisualization.transform.localScale = new Vector3(actualWidth, actualHeight, 1f)/quadSizeUnit;
}