美文网首页
unity UI 相机与 场景相机坐标的转换

unity UI 相机与 场景相机坐标的转换

作者: Albert_d37d | 来源:发表于2023-10-29 16:23 被阅读0次

Vector3 screenPos = Camera.main.WorldToScreenPoint(m_target.position);  //得到主相机屏幕坐标

  Vector2 position;

  RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("Canvas").GetComponent<RectTransform>(),screenPos,m_uiCamera, out position);  //param1  UI canvas     param2  UI相机    param3 输出坐标

  GetComponent<RectTransform>().anchoredPosition = position;

相关文章

网友评论

      本文标题:unity UI 相机与 场景相机坐标的转换

      本文链接:https://www.haomeiwen.com/subject/uhevidtx.html