当使用Screen Space-Camera,若未指定Render Camera,那么可以正常通过Input.mousePosition来获取当前屏幕中的鼠标位置,并应用在UI上(比如UI跟随鼠标)。若指定了相机,就必须使用RectTransformUtility.ScreenPointToWorldPointInRectangle来转换到UIcamera的世界坐标系。
同样,Camera.main.WorldToScreenPoint无法获取真正的UI屏幕坐标系。需要通过ScreenPoint坐标系来转换:
WorldPoint——>ScreenPoint——>UIpoint
使用Camera.main.WorldToScreenPoint获取ScreenPoint。使用RectTransformUtility.ScreenPointToLocalPointInRectangle获取UIpoint(这是LocalPosition)。