Time for action - compare the IDs

To compare the IDs, we need to make some changes to the FlipCardFaceUp function.

  1. Note that we're folding two existing lines of code inside a new conditional statement:
    function FlipCardFaceUp(card:Object)
    {
    card.isFaceUp = true;
    if(aCardsFlipped.IndexOf(card) < 0)
    {
    aCardsFlipped.Add(card);
    if(aCardsFlipped.Count == 2)
    {
    playerCanClick = false;
    yield WaitForSeconds(1);
    if(aCardsFlipped[0].id == aCardsFlipped[1].id)
    {
    // Match!
    aCardsFlipped[0].isMatched = true;
    aCardsFlipped[1].isMatched = true;
    }
    else
    {
    aCardsFlipped[0].isFaceUp = false;
    aCardsFlipped[1].isFaceUp = false;
    }
    aCardsFlipped = new ArrayList();
    playerCanClick = true;
    }
    }
    }
    

    Here, we check to see if the two flipped-over cards have the same ID value. ...

Get Unity 3D Game Development by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.