I’m new to unity and C# so I need some help. I’m making a simple card game. I’ve created a CARD class and a CardDatabase. I then created a PlayerDeck class that loads, shuffles and deal the cards. Here’s my PlayerDeck Class code:
public class PlayerDeck : MonoBehaviour
{
public List deck = new List();
public List container = new List();
public int x;
public int deckindex;
public GameObject cardobject, cardPrefab;
public GameObject panel;
void Start()
{
LoadCards();
Shuffle();
DealCards();
}
public void LoadCards()
{
x = 0;
for (int i = 0; i < 64; i++)
{
x = i;
deck = CardDatabase.cardList[×];
}
}
public void Shuffle()
{
for (int j = 0; j < 5; j++)
{
for (int i = 0; i < 64; i++)
{
container[0] = deck*;*
int rnd = Random.Range(i, 64);
deck = deck[rnd];
deck[rnd] = container[0];
}
}
}
public void DealCards()
{
cardobject = (GameObject) Instantiate(cardPrefab);
cardobject.transform.SetParent(panel.transform, false);
cardobject.GetComponent().sprite = deck[deckindex].thisImage;
}
// Update is called once per frame
void Update()
{
}
}
Everything is fine. The correct image loads on the gameobject. However I don’t know how to transfer the other crucial info using the GetComponent method for things like the CardID, card description, etc…
When I run this code, the PlayerDeck gameobject in the Hierarchy gets populated with the cards from the database (hence, the loading stage). The “deck” list has 64 elements. The elements are shuffled. Each element in the List has a name, id, description, value, image, and ability number. These are the pieces of info I need to access when I instantiate the cardprefab. Any help would be appreciated