- Home /
Question by
Ludwintor · Nov 10, 2020 at 03:53 AM ·
uiresolutionscaling
Unity UI resolution problem
Hi! I am faced with the problem of positioning maps at different screen resolutions
1920x1080
1280x720
As you can see, there is a different behavior of the location of the cards There is a script that align cards
private void AlignCards()
{
StopAllCoroutines(); // Stop all animations to start new TODO: Stop only card aligning coroutines, not all
float cardWidth = cardSize.x;
float offsetX = cardSize.x * offsetMultiplier - (cardList.Count * offsetMultiplier * cardSize.x * 0.4f);
float totalCardWidth = cardWidth + offsetX;
float totalWidth = cardList.Count * totalCardWidth;
for (int i = 0; i < cardList.Count; i++)
{
GameObject card = cardList[i];
if (card == currentCardDrag) continue;
Vector3 cardPos = card.transform.position;
cardPos.x = totalWidth * .5f - totalCardWidth * (cardList.Count - i) + totalCardWidth * .5f + transform.position.x; // Calculate position based on card order in a hand
cardPos.y = transform.position.y;
this.SmoothMovement(card.transform, cardPos, duration);
}
}
Card Size is
RectTransform cardRect = cardPrefab.GetComponent<RectTransform>();
cardSize = new Vector2(cardRect.rect.width, cardRect.rect.height);
1920x1080.png
(19.0 kB)
1280x720.png
(22.3 kB)
Comment
Best Answer
Answer by Ludwintor · Nov 10, 2020 at 05:20 AM
Okay I figured this out. Instead of translating transform.position you should translate transform.localPosition.