在不同屏幕尺寸上的矢量3位置

时间:2019-01-25 13:24:16

标签: c# unity3d

enter image description here

因此,当我在游戏中使用向量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;
    }

1 个答案:

答案 0 :(得分:1)

您正在寻找像<div class="col text-center"> <table class="table text-center"> <tbody id="table"> <tr> <td id="one">1</td> <td id="two">2</td> <td id="three">3</td> </tr> <tr> <td id="four">4</td> <td id="five">5</td> <td id="six">6</td> </tr> <tr> <td id="seven">7</td> <td id="eight">8</td> <td id="nine">9</td> </tr> </tbody> </table> <br /> <button class="btn btn-primary" type="button" id="start">Start Game</button> </div>这样的位置转换功能。这些可以在Unity Camera类文档中找到:https://docs.unity3d.com/ScriptReference/Camera.html

例如,如果您想要在屏幕的左上角放置一个Sprite,无论屏幕大小如何,都可以使用屏幕或视口空间。必须将精灵的位置从此屏幕/视口空间转换为世界空间。您可以为此使用Camera.ScreenToWorldPoint()

但是,Unity使用三个视区:屏幕,世界和视口。您应该仔细阅读这三个内容,因为您的问题源于您试图使用世界坐标(transform.position)来设置UI元素(使用屏幕或世界空间;这取决于父元素)的位置的事实。画布设置)

相关问题