[unity] canvas中世界坐标转化为本地坐标

   Vector3 buttonScreenPositionCamera.main.WorldToScreenPoint(_btnTagert.position);
            _btnTagert.SetParent(this.transform);
            _btnTagert.ResetLocalTransformation();
            buttonScreenPosition *= _rectTransform.sizeDelta.x / Screen.width;
            float newWidth = buttonScreenPosition.x - (_rectTransform.sizeDelta.x ) * 0.5f;
            float newHeight = buttonScreenPosition.y - (_rectTransform.sizeDelta.y) * 0.5f;
            _btnTagert.localPosition = new Vector3(newWidth, newHeight, 0);

你可能感兴趣的:(unity,游戏引擎)