- Home /
How to get suit of card and count
I have set the suit for each of the card. Now i want get the suit the the card and count the total. Can anyone tell me how to make it?
This is the method i use to set suit to each card
private string suitString;
public SUIT suit = SUIT.DIAMOND;
public enum SUIT
{
DIAMOND,
CLUB,
HEART,
SPADE
}
// Start is called before the first frame update
void Start()
{
if (CompareTag("Card"))
{
suitString = transform.name[0].ToString();
if (suitString == "D")
{
suit = SUIT.DIAMOND;
}
if (suitString == "C")
{
suit = SUIT . CLUB;
}
if (suitString == "H")
{
suit = SUIT .HEART;
}
if (suitString == "S")
{
suit = SUIT .SPADE;
}
}
}
Example
In this Picture has total 2 diamonds,5 clubs,1 heart, and 5 spades.
First i want to get the suit of those cards.
Second i count the total of each suit.
Answer by Zaeran · Sep 08, 2020 at 04:14 PM
First off, you'll need a script that acts as a counter that you can call from each card.
Dictionary<SUIT, int> suits = new Dictionary<SUIT, int>();
void Awake(){
suits.Add(<script>.SUIT.Heart, 0); //do this for all suits
}
Public void RegisterSuit(SUIT suit){
suits[suit]++;
}
Then you can call the RegisterSuit function from each of your cards, and poll the dictionary to get the count.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Stack Card 0 Answers
Flip over an object (smooth transition) 3 Answers