unit 模型的位置坐标转换到UI坐标

    /// 
    /// 相机
    /// 
    public Camera m_Camera;
        /// 
    /// UI按钮
    /// 
    public RectTransform UIBtn;
    void Update()
    {
            //坐标转换 世界转屏幕
            Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(m_Camera, transform.position);
            Vector2 localPoint;
            //坐标转换 屏幕转UI
            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasTran, screenPoint, m_Camera, out localPoint))
            {
                UIBtn.anchoredPosition = localPoint;
            }
    }
       

你可能感兴趣的:(unity)