using System; using UnityEngine; public class CardCollector : MonoBehaviour { private Card _firstCard; private Card _secondCard; public void FindCards() { Card[] cards = FindObjectsOfType(); for (int i = 0; i < cards.Length; i++) { cards[i].SetCardCollector(this); } } public void OpenCard(Card card) { if(_firstCard == null) _firstCard=card; else { _secondCard=card; Invoke(nameof(CompareCards), 0.8f); } } private void CompareCards() { if (_firstCard.Index == _secondCard.Index) { Destroy(_firstCard.gameObject); Destroy(_secondCard.gameObject); } else { _secondCard.CardAnimation(); _firstCard.CardAnimation(); } _secondCard = null; _firstCard = null; } public bool TwoCardsClosed() { return _secondCard==null; } }