how to align my cards like this ?

hi all

I have following code for my card game and I need to align the cards like below and not getting an idea how to show. I am very new to Unity and C#
The image can be seen here

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour {
public Sprite[] card;
void Awake()
{
// load all frames in cards array
card = Resources.LoadAll<Sprite>("CardDeck_");
}
void Start ()
{
// create the object
GameObject cards = new GameObject();
// add a "SpriteRenderer" component to the newly created object
cards.AddComponent<SpriteRenderer>();
cards.GetComponent<SpriteRenderer>().sprite = card[8];
cards.GetComponent<SpriteRenderer>().sprite = card[15];
}
}

3262616--251661--card-align-sample.PNG

You would use a for loop to arrange those sprites. But you’re not to that point yet. Right now, you’re just creating one card, whose image looks like sprite 8 no actually sprite 15.

So the next step is probably to change this to a List cards, or better yet, List cards. Then create an object for card[0], and add it to this list. Then also create an object for card[1], and add that to the list as well. Then, because you’re already starting to get tired of copying & pasting by this point, change it to use a for-loop to create objects for all the cards you have.

Once you’ve done all that, then you should be asking how to position these cards so they’re not all at 0,0,0. And it’ll be pretty easy by that point — just a bit of math based on cards.Count, and use that to assign the position of each new card.

If you haven’t done it already, I highly recommend working through both some Unity tutorials (follow the Learn link at the top of this page), and some C# tutorials. Trying to learn this stuff as you go is going to be much, much harder than getting some instruction up front.

Good luck with your game, and enjoy the journey!