UnityEngine.RectTransformUtility.ScreenPointToRay C# (CSharp) Method

ScreenPointToRay() public static method

public static ScreenPointToRay ( Camera cam, Vector2 screenPos ) : Ray
cam Camera
screenPos Vector2
return Ray
        public static Ray ScreenPointToRay(Camera cam, Vector2 screenPos)
        {
            if (cam != null)
            {
                return cam.ScreenPointToRay((Vector3) screenPos);
            }
            Vector3 origin = (Vector3) screenPos;
            origin.z -= 100f;
            return new Ray(origin, Vector3.forward);
        }

Usage Example

コード例 #1
0
        public static bool ScreenPointToWorldPointInRectangle(RectTransform rect, Vector2 screenPoint, Camera cam, out Vector3 worldPoint)
        {
            worldPoint = (Vector3)Vector2.zero;
            Ray   ray = RectTransformUtility.ScreenPointToRay(cam, screenPoint);
            float enter;

            if (!new Plane(rect.rotation * Vector3.back, rect.position).Raycast(ray, out enter))
            {
                return(false);
            }
            worldPoint = ray.GetPoint(enter);
            return(true);
        }
All Usage Examples Of UnityEngine.RectTransformUtility::ScreenPointToRay