0

I know this is a popular Question, but unfortunately no of the solutions work for me. So basically what I try to do is creating an Trading Card Game in Unity. I have a Script called "Card" that is basically "what is a card". The script does NOT derive from MonoBehaviour, what means I can use constructors right ?

// Construktor 
public Card (string name, string info, string rar, string edi, int id){
    cardName = name;
    switch (rar) {
    case "Common":
        rarity = Rarity.Common;
        break;
    case "Rar":
        rarity = Rarity.Rar;
        break;
    case "Epic":
        rarity = Rarity.Epic;
        break;
    case "Legendary":
        rarity = Rarity.Legendary;
        break;



    }

    cardInfo = info;


    switch (edi) {
    case "Normal":
        edition = Edition.Normal;
        break;

    case "Special":
        edition = Edition.Special;
        break;

    }

    cardId = id;
    picture = Resources.Load<Sprite>("Cards/" + name );



}

Okay so the Player should have a script called "CardCollection" with is his Collection of Cards. In this Script I want a List of Cards. But when I do something like

    public List<Card> cardCollection;
....
    cardCollection.Add (new Card ("Alex","whatever", "Rar", "Normal", 0001));

I do get: NullReferenceException: Object reference not set to an instance of an object CardCollection.Start () (at Assets/Scripts/SideScroll/CardCollection.cs:24)

And I don't know why, where is my mistake ?

0 Answers0