Z
Z
Zimaell2020-12-25 11:58:53
Unity
Zimaell, 2020-12-25 11:58:53

How to bind objects to panel position?

There is a panel smaller than the screen area in the center, objects are displayed in it, the question is how to make the coordinates of these objects start from the border of this panel and not from the screen coordinates?
I initialize like this

public Cell2 cell2;
    public GameObject PanelBoard;
    public Dictionary<string, Cell2> Cells2 = new Dictionary<string, Cell2>();

    void InitializationBoardTest(){
        for(int y = 0; y < BoardHeight; ++y){
            for(int x = 0; x < BoardWidth; ++x){
                string yx = y + "-" + x;
                Cells2[yx] = Instantiate(cell2, new Vector3((x * 100), (y * 100), 0), Quaternion.identity) as Cell2;
                Cells2[yx].transform.parent = PanelBoard.transform;
                }
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GFX Data, 2020-12-25
@ShockWave2048

I would add a container to the panel, Vertical/Horizontal/Grid Group. It will automatically level up new heirs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question