public void ShowCards(List <BaseCard> cardsOrg) { cards = new List <BaseCard>(cardsOrg); cardPanel.SetActive(true); cardPanel.transform.SetAsLastSibling(); int numberOfCards = cards.Count; int currentCard = 0; if (numberOfCards <= 5) { for (int i = 0; i < numberOfCards; i++) { tempCard = Instantiate(cards[currentCard], cardPanel.transform); newCardPosition.y = (0 + (distanceBetweenCardsY * 2)); newCardPosition.x = ((-distanceBetweenCardsX * 2) + (distanceBetweenCardsX * i)); currentCard++; Debug.Log(newCardPosition); tempCard.GetComponent <RectTransform>().anchoredPosition = newCardPosition; tempCard.GetComponent <BaseCard>().ExampleCard(); } } else { for (int row = 0; row <= (numberOfCards / 5); row++) { for (int coll = 0; coll < 4; coll++) { if (cards.Count < currentCard + 1) { return; } tempCard = Instantiate(cards[currentCard], cardPanel.transform); newCardPosition.y = ((distanceBetweenCardsY * 2) - (distanceBetweenCardsY * row)); newCardPosition.x = ((-distanceBetweenCardsX * 2) + (distanceBetweenCardsX * coll)); currentCard++; tempCard.GetComponent <RectTransform>().anchoredPosition = newCardPosition; tempCard.GetComponent <BaseCard>().ExampleCard(); } } } }