I'm busy trying to make a game in Unity3D, but haven't had much experience in C# and having some trouble finding any specifics on how value/reference types are handled. I understand the basics of it; that most primitive data types, structs and enums are value type (unless specified by the ref qualifier), and all classes are reference types. Knowing that, I'm assuming the code I've currently got isn't working the way I meant it to because of my lack of knowledge. I'm trying to make a fairly simple card game, and have a Hand class, and a Deck class, both of which are simply containers for Card objects.
public class Deck
{
private List<GameObject> cards;
private const int TOTAL_CARDS = 52;
private int iterator;
//Constructors...
public GameObject drawCard()
{
if (cards.Count == 0)
{
//Merge discard pile with deck
}
GameObject temp = cards[iterator];
cards.RemoveAt(iterator++);
return temp;
}
}
public class Hand{
private List<GameObject> cards;
private int numCards;
private Deck deck;
public Hand(Deck deck)
{
this.deck = deck;
numCards = 0;
cards = new List<GameObject>(15);
}
public void drawCard()
{
GameObject card = deck.drawCard();
Transform cardTransform = card.transform;
cardTransform.position.Set(1, 1, 1);
cardTransform.Rotate(new Vector3(0, 1, 0), 180);
cards.Add(card);
numCards++;
}
}
Above is a simplified version of those two classes, the methods the question pertains to is the drawCard() methods in both classes. In the Deck's drawCard method, would removing the object from the List remove a reference or an object; and would the object returned by that method and used in the Hand's drawCard method be a reference pointing to an object that has been deleted(removed from the list) or will it be retained?
Thanks for any help.