Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
I need help to define an architecture for my card game in Unity

I am currently working on a game inspired by Ratropolis in Unity, which means that the player will have to play cards from his hand to achieve certain actions in the world, like get some money or this kind of things.

I am not sure how to implement this, and I am very confused to say the least. Basically, so far I had been using a Scriptable Object called CardData, which looks like this : (please note that the CardsEffect line was not present until yesterday, and this is what I am confused about)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
 
[CreateAssetMenu]
public class CardData : ScriptableObject
{
    //This will contain all the cards information.
    public string cardName, description;
    public int moneyCost, natureCost, foodCost;
    public Texture2D texture; //this is for prototyping only, textures will be replaced by a prefab.
    public CardsEffect cardEffect; // CardsEffect is a public class that I created for my spells class to Inherit from. I am not sure about this tho
}

Searching online, I saw that many people recommanded to create a public class that would hold the voids of the effects, so I could create a class for each card inheriting from it. So this is what I did :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
 
[System.Serializable]
public class CardsEffect
{
    private GameObject resourceController;
    public CardsEffect()
    {
 
    }
 
    public bool unplayable;
 
    [Header("When played")]
    public int moneyBonus;
    public int natureBonus;
    public int foodBonus;
 
    [Header("When drawn")]
    public int drawMoneyBonus;
    public int drawNatureBonus;
    public int drawFoodBonus;
   
    public void OnDraw()
    {
 
    }
 
    public void OnPlay()
    {
 
    }
}

But I realize I don't really know how to use this. Basically, what I was thinking about was creating public voids in the CardsEffect class with parameters, like this so I could easily call the voids from the inheriting classes, but I'm not sure it's good.

DrawCards(int cardsToDraw)
{
  target player draws cardsToDraw cards;
}

Also, I don't understand how to implement these classes since they don't inherit from MonoBehaviour, I can't attach them to my ScriptableObject, and I can't make a CardsEffect using the voids. So as you can see, I am very confused, and I would really appreciate some advices about this.

Thanks for reading me, Best regards

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

My suggestion is to separate your data and game play logic into different classes. Logic class say CardCtrl inherits from MonoBehaviour, and data class does not. CardCtrl is attached to the Card game object. Card data are just instances in the memory. Could be referenced in the CardCtrl.

You need to create a DataManager class to initialize or load those card data instances when needed. Do not be afraid of creating too many classes.

Simple sample:

// put each class in a new `cs` script with proper name(same with class name).
public class CardData
{
    public int key;
    public int attack;
    public int cost;
    // other data you need
}

public class CardDataMgr: MonoBehaviour  // attach this to a game object
{
    Dictionary<int, CardData> dataDict = new Dictionary<int, CardData>(); // the int here is card data key
    private void Awake()
    {
        LoadData();
    }
    public void LoadData()
    {
        // load from files or codes or server
        dataDict.Add(1, new CardData() { key = 1, attack = 100, cost = 100 }); // besure the keys are the same
        dataDict.Add(2, new CardData() { key = 2, attack = 100, cost = 100 });
    }

    public CardData GetCardData(int key)
    {
        return dataDict[key];
    }
}

public class CardCtrl: MonoBehaviour // attach this to the card prefab or card game object
{
    int key;
    int cost;
    int attack;

    public void InitWithCardKey(CardDataMgr mgr, int key) // call this when you need a new Card, pass in the CardDataMgr in the scene(or you could make it into a singleton)
    {
        this.key = key; // take a record of key in case for future usage
        var data = mgr.GetCardData(key);
        this.cost = data.cost;
        this.attack = data.attack;
    }

    // following are other logic that you need
    public void OnDraw()
    {

    }

    public void OnKilled()
    {

    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!