So I’m pretty sure I’m just misunderstanding how part of my code is working right now, or there might be a normal old Null Reference somewhere that I’m not seeing.
When I call DrawCard() the Null Reference exception is thrown.
// Draw the top card of the deck.
public void DrawCard () {
Card c = CreateInstance<Card>();
c = library.RemoveCard(0);
hand.AddCard(c);
Debug.Log ("Cards in deck: "+library.cardsInLibrary+" Cards in hand: "+hand.cardsInHand);
}
Hand Class:
public class Hand : ScriptableObject {
public int maxHandSize = 7;
public int cardsInHand;
public Card[] contents;
void Start () {
LoadHand ();
}
void Update () {
}
void LoadHand () {
for(int i=0; i<maxHandSize; i++){
contents *= CreateInstance<Card>();*
-
}*
-
}*
-
public void AddCard (Card c) {*
-
Card[] a = new Card[cardsInHand+1];*
-
for(int i=0; i<cardsInHand+1; i++){*
-
if(i==cardsInHand)*
a = contents*;*
* if(i==cardsInHand+1)*
_ a = c;
* }*_
* contents = a;*
* cardsInHand++;*
* }*
}
Deck Class:
public class Deck : ScriptableObject {
* public int deckSize = 60;*
* public int cardsInLibrary;*
* public Card[] contents;*
* void Start () {*
* LoadDeck ();*
* ShuffleDeck ();*
* }*
* void Update () {*
* }*
* // Creates the deck contents array and populates it.*
* void LoadDeck(){*
* contents = new Card[deckSize];*
* cardsInLibrary = contents.Length;*
* for(int i=0; i<deckSize; i++){*
_ contents = CreateInstance();
* }*_
* // Temporarily assigns the Cards in the array with names.*
* for(int i=0; i<deckSize; i++){*
_ contents*.cardName = “Card #”+(i+1);
}
}*_
* // Removes the c position card in the Deck contents and returns the removed card.*
* public Card RemoveCard(int n){*
* Card removedCard = new Card();*
* Card[] a = new Card[cardsInLibrary-1];*
* for(int i=0; i<cardsInLibrary-1; i++){*
* if(i!=n){*
a = contents*;*
* }*
* if(i==n){*
_ removedCard = a*;
}
}*_
* contents = a;*
* cardsInLibrary–;*
* return removedCard;*
* }*
* //Randomize the contents array.*
* public void ShuffleDeck(){*
* for(int i=0; i<deckSize; i++){*
* //int r = Random.Range (1, 60);*
* }*
* }*
}
Player Class:
public class Player : ScriptableObject {
* public string playerName;*
* public bool isOnPlay;*
* public Phases currentPhase;*
* public int life;*
* public int playerTurn;*
* // GAME ZONES*
* public Deck library;*
* public Hand hand;*
* public Graveyard graveyard;*
* public Exile exile;*
* // DEFINE THE PHASES OF A TURN*
* public enum Phases{*
* Untap,*
* Upkeep,*
* Draw,*
* Main1,*
* DeclareAttackers,*
* DeclareBlockers,*
* FirstStrikeCombatDamage,*
* CombatDamage,*
* Main2,*
* End,*
* Cleanup*
* }*
* void Start () {*
* library = CreateInstance();*
* hand = CreateInstance();*
* }*
* void Update () {*
* }*
* // Draw the top card of the deck.*
* public void DrawCard () {*
* Card c = CreateInstance();*
* c = library.RemoveCard(0);*
* hand.AddCard(c);*
* Debug.Log ("Cards in deck: “+library.cardsInLibrary+” Cards in hand: "+hand.cardsInHand);*
* }*
}