如题,本人新人,不知道这种方法会不会引发一些bug,但总之就发出来请各位大佬点评一哈了。哦对,我的编译器版本是2021.3.6f1c1
public static Vector3 UIPostoScreenPos(Canvas canvas,Vector3 uipos)
{
float width = canvas.GetComponent<RectTransform>().rect.width;
float height = canvas.GetComponent<RectTransform>().rect.height;
float screenWidth = UnityEngine.Screen.width;
float screenHeight = UnityEngine.Screen.height;
uipos = new Vector3((uipos.x * (screenWidth / width)) + (screenWidth / 2),
uipos.y * (screenHeight / height) + (screenHeight / 2),
0);
return uipos;
}
呐,大概就是这样。