,Comparing game object tag to variable help.

Noob here, slowly learning.

I’m having trouble working out how to compare a tag to an int variable. The tags on certain cards are “0”, “1”, & “2”.

My cardCount variable resets every 3 cards. I would like to execute a method if the cardCount and the tag align.

Apologies if this is super basic.
Thanks in advance.

public List<Card> deck = new List<Card>();

public int cardCount = 0;

public void DrawCard()
{
    if (deck.Count >= 1)
    {
        if (cardCount <= 2)
        {
            Card randCard = deck[Random.Range(0, deck.Count)];

            **if (randCard.CompareTag.(cardCount))**
            {
                Debug.Log("game over");
            }

            randCard.gameObject.SetActive(true);
            deck.Remove(randCard);
            cardCount++;
        }

        else
        cardCount = 1;

,Noob here, slowly learning.

I’m having trouble working out how to compare a tag to an int variable. The tags one certain cards are “0”, “1”, & “2”.

My cardCount variable resets every 3 cards. I would like to execute a method if the cardCount and the tag align.

Apologies if this is super basic.
Thanks in advance.

public List<Card> deck = new List<Card>();

public int cardCount = 0;

public void DrawCard()
{
    if (deck.Count >= 1)
    {
        if (cardCount <= 2)
        {
            Card randCard = deck[Random.Range(0, deck.Count)];

            **if (randCard.CompareTag.(cardCount))**
            {
                Debug.Log("game over");
            }

            randCard.gameObject.SetActive(true);
            deck.Remove(randCard);
            cardCount++;
        }

        else
        cardCount = 1;

Not fully sure why you’re doing it this way, but compare tag only reads a string as far as the documentation shows: Unity - Scripting API: Component.CompareTag

and as you will see in the documentation example the parenthesis need to be with CompareTag(). So a simple setter of your cardCount in StringToInt() as a string, and the string within the compare parenthesis, should fix your problem.

but I feel you would learn a lot more by researching into Singletons, and static variables :wink: :wink: