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

2023-10-29  本文已影响0人  Albert_d37d

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;

上一篇 下一篇

猜你喜欢

热点阅读