示例#1
0
    /// <summary>
    /// Handle cards selection
    /// </summary>
    /// <param name="card"></param>
    public void HandleCardSelected(PlayerCard card)
    {
        // 1st case: no cards clicked yet, set and reveal 1st card
        if (firstCardOfPair == null)
        {
            firstCardOfPair = card;
            firstCardOfPair.RevealCard();
        }
        // 2nd case: 1 card has been clicked, set and reveal 2nd card
        else if (secondCardOfPair == null)
        {
            secondCardOfPair = card;
            secondCardOfPair.RevealCard();

            // Check if cards match
            if (firstCardOfPair.Id != secondCardOfPair.Id)
            {
                // No match, flip cards back
                StartCoroutine(WaitBeforeFlippingBack());
            }
            else
            {
                // Match found, clear selected cards
                firstCardOfPair  = null;
                secondCardOfPair = null;
            }
        }
    }