I don't know exactly what I'm Asking... (Arrays)

I have this script that will output a shuffled deck of 52 cards beautifully to the console. Now I’m trying to check the output name so I can assign each sprite to that name of the card. Example if output is “Ace Of Spades” then display the sprite of Ace Of Spades. Totally lost here.

using UnityEngine;
using System.Collections;

public class DeckOfCards : MonoBehaviour {

    private Card[] deck; // array of cards for the deck from Card.cs
    private int currentCard; // know what card we are on out of the deck
    private const int NUMBER_OF_CARDS = 52; // constant value of 52 this never changes
    public System.Random ranNum = new System.Random(); // for making a random number to shuffle


    public DeckOfCards() // constructor to default deck of cards
    {
         string [] faces = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace"}; //array of this type
         string [] suits = {"Clubs", "Spades", "Hearts", "Diamonds"}; // array of this type
   
        deck = new Card[NUMBER_OF_CARDS]; // create a new deck with 52 cards from the card class or Card.cs
        currentCard = 0; // the current card needs to be zero at start
        ranNum = new System.Random (); // create a random number
   
        for (int count = 0; count < deck.Length; count++) // count starts at zero. While count is less than the deck size then count.
        {
            deck[count] = new Card (faces[count % 13] , suits[count / 13]); // so starts at 0 adds a face then "Of" then adds suit
        }
   




        if (faces.Equals("One") && suits.Equals("Clubs"))
        {
            print("test test test ");

        }
   
    }


    public void Shuffle() // shuffle the deck
    {
        currentCard = 0; // always start over when shuffle make current card 0
        for (int first = 0; first < deck.Length; first ++)
        {


            int second = ranNum.Next(NUMBER_OF_CARDS); // pull out a card of the deck
            Card temp = deck[first]; // set first card into temp
            deck[first] = deck[second]; // set the first card into second
            deck[second] = temp; // then put the card back into first?
       
       
        }
   
    }
        public Card DealCard() // deal the cards
        {
        if(currentCard < deck.Length) // if cards exist
        {
            return deck[currentCard++]; // return card then return next
        }
        else {
            return null; // stop return nothing
   
        }
   
   
}





    void Update()
    {
           
    }





}

Display Code

using UnityEngine;
using System.Collections;

public class PrintCard : MonoBehaviour {

    // Use this for initialization
    private DeckOfCards deal;
    void Awake()
    {
        deal = gameObject.GetComponent<DeckOfCards>();

    }

    void Start ()
    {
        DeckOfCards deck1 = new DeckOfCards (); // create a deck
        deck1.Shuffle(); // shuffle the deck

        for(int i = 0; i < 52; i ++)
        {
            print( deck1.DealCard());
        }
        if(deck1.name.Equals("One Of Clubs"))
        {
            print("fkfkfkfkfkf");
       
        }
    }
   
    // Update is called once per frame
    void Update ()
    {
       
    }


   


}

I made a solitaire in unity, so had to tackle this sort of thing. I’d say keep face value as integers, rather than strings (maybe 1 through 13), although if this is a card game with slow pace it won’t really matter.

And so you’ll need sprites for the visuals of the entire deck, and a prefab for a gameobject they can be assigned to. You could use either ui images, or just regular sprite gameobjects. You probably should assign a script to them that keeps info like face value and suit, and as your “dealing” the cards (probably some animation) you keep populating that scripts variables so later you can check it in comparisons. When your shuffling and moving to foundations, or whatever, you assign the sprite based on the shuffle, probably with a few loops that create a path to a resource to load the sprite (that’s how I did it for simplicity) and assign it.

For the suit you could use char like ‘d’ / ‘h’ / ‘s’ / ‘c’ instead of a whole string, and check in comparisons that way.

This means during assignment of textures you could do something like “if (thisCard.suit == ‘d’) { path = thisCard.value.ToString () + “_d”}; // load from resources or something”

Hope that helps get you started!