Hi everyone,
I am having a problem with my code.
What is supposed to do is go trough a list affecting the first part of a list is supposed to be changed into type A, and the second part is supposed to assign type B.
This is my code
void AssignLetter ()
{
for (int i = 0; i< 20 ; i++)
{
if (i < 10 )
{
currrentDeck*.letter = PlayerCard.CardType.A;*
_ currrentDeck*.letter = PlayerCard.CardType.B;_
_ }_
_ }*_
* }*
I tried to debug the code, and what it does is, that when it enters the second if, it changes ALL the objects from the list to B. Even the one with index[0]. My logic was that it should change only the item index*.*
public void CreateDeck()
{
// This will add card1Start number of copies of a
// reference to templateCards[0], so disregardless
// of which card in cuRRRentDecks we use, we will
// always use that same card.
//
// currrectDeck[3] will be the same as currrentDeck[5]
// for example.
for (int i = 0; i < card1Start; i++)
{
currrentDeck.Add(templateCards[0]);
}
}
So, currrentDeck (with 3 R, nice, spice it up a little :)) will always reference the same card. Accessing any card in the current deck of cards, will give you the same card. Instead, consider instantiating a copy of the template card and use that instead:
public void CreateDeck()
{
// This will add new instances of templateCards[0].
// Each card in the deck references a unique card.
//
// currrectDeck[3] will be different from currrentDeck[5]
// for example.
for (int i = 0; i < card1Start; i++)
{
currrentDeck.Add(Instantiate(templateCards[0]));
}
}