[英]Vector 3 Position on different Screen Size
因此,當我在游戲中使用向量3時,我希望向量3在不同屏幕尺寸的特定位置上會發生什么? 那可能嗎? 這是我的密碼
public virtual void ShuffleButton()
{
Vector3 buttonFirst = gameButtons[0].transform.position;
buttonFirst.x += 297f;
gameButtons[0].transform.position = buttonFirst;
Vector3 buttonSecond = gameButtons[1].transform.position;
buttonSecond.x -= 74.25f;
gameButtons[1].transform.position = buttonSecond;
Vector3 buttonThird = gameButtons[2].transform.position;
buttonThird.x += 74.25f;
gameButtons[2].transform.position = buttonThird;
Vector3 buttonFourth = gameButtons[3].transform.position;
buttonFourth.x -= 148.5f;
gameButtons[3].transform.position = buttonFourth;
Vector3 buttonFifth = gameButtons[4].transform.position;
buttonFifth.x -= 148.5f;
gameButtons[4].transform.position = buttonFifth;
}
您正在尋找位置轉換功能,例如Camera.ScreenToWorldPoint()
。 這些可以在Unity Camera類文檔中找到: https : //docs.unity3d.com/ScriptReference/Camera.html
例如,如果要將Sprite放置在左上角,而不考慮屏幕大小,則可以使用屏幕或視口空間。 必須將精靈的位置從此屏幕/視口空間轉換為世界空間。 您可以Camera.ScreenToWorldPoint()
使用Camera.ScreenToWorldPoint()
。
但是,Unity使用三個視區:屏幕,世界和視口。 您應該仔細閱讀這三個內容,因為您的問題源於您試圖使用世界坐標(transform.position)來設置UI元素(使用屏幕或世界空間;這取決於父元素)的位置的事實。畫布設置)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.