Keeping card variables together

I have a card game where each card has four values (type, value, cost, price) they each change but each can’t be dynamically assigned because each card is different. Some example cards are |Attack, 4, 7, 10| in which the card is an attack card, that deals 4 damage, costs 7 action points to cast and costs 10 dollars to buy. |Block, 6, 15, 50| is a card that blocks 6 points of damage, costs 15 ap to play and costs 50 dollars to buy. What is the best way to keep these values constant and together. I have been looking at a few ways but I’m not sure.

Create an enum to store the type

public enum CardType

Create a class to hold each cards values.

public class Card
    public CardType type;
    public int card_value, card_apCost, card_costToBuy;

    Public Card(CardType type, int value, int apCost, int costToBuy)
         card_type = type;
         card_value = value;
         card_pCost = apCost;
         card_costToBuy = costToBuy;

Then create a Script Component for each card and give it an instance of the Card Class to store it’s values?

Unsure if you wanted JavaScript, it shouldn’t be too hard to translate.

Note that that data structure is pretty unsafe - unsure if you’re concerned about that.

For instance you could add some encapsulation to protect the values by using getters/setters - like so:

  public int card_Value { get; private set; } 

Now you can only set the card_Value inside the class, so to set it from outside you’d need to add an accessor method - like so:

 public void Set_Card_Value(int value)
      //Add some validation logic if required - such as 
      if(value < 0)
            value = 1;
            card_Value = value;

Also note that if you do not add an accessor method and use the { get; private set; } getter/setter as stated above, the value is going to be immutable (a constant value).

Going on from your comment:

Create a gameObject to use as a prefab, then attach a script component to it. Let’s just say it’s called ScriptOne for simplicity.

 public class ScriptOne : MonoBehavior

      public Card the_instance_I_Was_Talking_About;

      void Awake()
           the_instance_I_Was_Talking_About = new Class(CardType.attacking,


How you want to assign the values in awake i’m unsure, i’d need to know more about your game… But yeah, now accessing that, is as simple as calling .GetComponent().

Something like this - assuming you assigned the object with a tag in this instance.

 void SomeFunctionElseWhere()

      int x = GameObject.FindGameObjectWithTag("WhateverTagYouUsed")


Note that the ‘ScriptOne’ in the above .GetComponent should be enclosed in those triangles (Chevrons? lol), but they don’t show up in the answer so I used brackets instead.