Question by
SerpiPliskin · Jul 12, 2021 at 11:59 PM ·
resolutionscalerecttransformpaneltweening
RectTransform size aspect ratio
I try to have different panels outside the screen, adjusted to the center panel.
But when the resolution changes, for example in 800x480, some gaps appear between the panels.
My intention is to make the panels fit tightly and make them slide without interfering with each other, but I can't do it without having the correct starting coordinates.
public RectTransform mainPanel, rightPanel, leftPanel, topPanel, bottomPanel;
public Vector2 centerPosition, rightPosition, leftPosition, bottomPosition, topPosition;
void Awake()
{
// Assign position to each panel
centerPosition = new Vector2(0f, 0f); // Center
rightPosition = new Vector2(mainPanel.sizeDelta.x, 0f); // Right
leftPosition = new Vector2(-mainPanel.sizeDelta.x, 0f); // Left
topPosition = new Vector2(0f, mainPanel.sizeDelta.y); // Top
bottomPosition = new Vector2(0f, -mainPanel.sizeDelta.y); // Bottom
// Move the panels to their starting positions
mainPanel.DOAnchorPos(centerPosition, 0f);
rightPanel.DOAnchorPos(rightPosition, 0f);
leftPanel.DOAnchorPos(leftPosition, 0f);
topPanel.DOAnchorPos(topPosition, 0f);
bottomPanel.DOAnchorPos(bottomPosition, 0f);
}
Comment
I have also tried Screen.width and Screen.Height but the same thing happens.
public RectTransform mainPanel, rightPanel, leftPanel, topPanel, bottomPanel;
public Vector2 centerPosition, rightPosition, leftPosition, bottomPosition, topPosition;
void Awake()
{
// Assign position to each panel
centerPosition = new Vector2(0f, 0f); // Center
rightPosition = new Vector2(Screen.width, 0f); // Right
leftPosition = new Vector2(-Screen.width, 0f); // Left
topPosition = new Vector2(0f, Screen.height); // Top
bottomPosition = new Vector2(0f, -Screen.height); // Bottom
// Move the panels to their starting positions
mainPanel.DOAnchorPos(centerPosition, 0f);
rightPanel.DOAnchorPos(rightPosition, 0f);
leftPanel.DOAnchorPos(leftPosition, 0f);
topPanel.DOAnchorPos(topPosition, 0f);
bottomPanel.DOAnchorPos(bottomPosition, 0f);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613040242im_/https://answers.unity.com/themes/thub/images/avi.jpg)