public AsyncState CardDealing(int numberOfPairs) { if (HelpButton != null) { HelpButton.interactable = true; } IsFinishGameRound = false; var asyncChain = Planner.Chain(); asyncChain.AddAction(Debug.Log, "Dealing started"); IsDealing = true; var movePosition = new Vector3(-1.0f, 0.0f, 0f); var moveOffset = Vector3.right * 0.8f; for (var i = 0; i < numberOfPairs * 2; i++) { CardBehaviour card = null; var instancePosition = new Vector3(0f, 0.2f, 10f); var instanceRotation = _cardPrefab.transform.rotation; if (CardsPool.Count > i && !CardsPool[i].GameObject.activeSelf) { CardsPool[i].Transform.position = instancePosition; CardsPool[i].Transform.rotation = instanceRotation; card = CardsPool[i].GameObject.GetComponent <CardBehaviour>(); card.SetImage(GetImage(i)); card.gameObject.SetActive(true); asyncChain.AddFunc(card.MoveToTable, movePosition); movePosition += moveOffset; continue; } var cardFactory = new CardFactory(); var cardObject = cardFactory.CreateCard(instancePosition, instanceRotation); CardsPool.Add(cardObject); card = cardObject.GameObject.GetComponent <CardBehaviour>(); card.SetImage(GetImage(i)); asyncChain.AddFunc(card.MoveToTable, movePosition); movePosition += moveOffset; } asyncChain.AddFunc(_difficultyController.ShowCardsInBeginning, CardsPool); asyncChain.AddAction(Debug.Log, "Dealing finished"); asyncChain.onComplete += () => IsDealing = false; return(asyncChain); }