I am trying to convert the position of a UI Selection Box, into world coordinates, so that I can select items which correspond with world space positions.
For some reason, my example function below shows that coords1 and coords2 are not identical positions, however once they are converted to ScreenToWorldPoint, they both take on an identical position of the cameras gameObject.
mousePos1 is a variable which is set earlier on, when the left mouse button is downed, once the button is released coords2 is set to the new mouse position.
void GetSelectionBoxCoords()
{
Vector3 coords1 = mousePos1;
Vector3 coords2 = Input.mousePosition;
Debug.Log("coords1 is " + coords1.ToString() + " and coords2 is " + coords2.ToString());
Vector3 coordsToCam1 = myCam.ScreenToWorldPoint(coords1);
Vector3 coordsToCam2 = myCam.ScreenToWorldPoint(coords2);
Debug.Log("coordsToCam1 is " + coordsToCam1.ToString() + " and coordsToCam2 is " + coordsToCam2.ToString());
}
Why is ScreenToWorldPoint producing the exact value of the cameras location? Can anyone help. I am using Unity 5.6.
Thank you