This seems to work well enough for me with a plane and a camera in the variables:
Vector3 mousePosition = Input.mousePosition;
Ray screenPosition = _cam.ScreenPointToRay (mousePosition);
if (!_plane.GetComponent ().Raycast (screenPosition, out RaycastHit hit, 1000))
{
return;
}
Vector3 hitPoint = _cam.WorldToScreenPoint (hit.point);
Vector3 planeMin = _cam.WorldToScreenPoint (_plane.GetComponent ().bounds.min);
Vector3 planeMax = _cam.WorldToScreenPoint (_plane.GetComponent ().bounds.max);
float xProportion = Mathf.InverseLerp (planeMin.x, planeMax.x, hitPoint.x);
float yProportion = Mathf.InverseLerp (planeMin.y, planeMax.y, hitPoint.y);
float xPoint = xProportion * sourceImage.width;
float yPoint = yProportion * sourceImage.height;
Vector2 startPosition = new Vector2 (xPoint, yPoint);
↧
Trending Articles
More Pages to Explore .....