public void ShowCards(int _invalidWantPosID) { if (cards.Count > 0) { foreach (GameObject thisCard in cards) { Destroy(thisCard); } cards.Clear(); } int cardCount_x = 0; int cardCount_y = 0; int cardCount = 0; int rightAnswerPos = Random.Range(0, deckModel.elemCount); while (rightAnswerPos == _invalidWantPosID && deckModel.elemCount > 2) { rightAnswerPos = Random.Range(0, deckModel.elemCount); } foreach (int i in deckModel.GetCards()) { GameObject cardCopy = (GameObject)Instantiate(cardPrefab); cards.Add(cardCopy); CardModel cardModel = cardCopy.GetComponent <CardModel>(); float offsetX = cardOfset_x * cardModel.rectSizeX * cardCount_x; float offsetY = cardOfset_y * cardModel.rectSizeY * cardCount_y; float zlevel = 0.01f * cardCount + 0.01f; Vector3 temp = startPos + new Vector3(offsetX, -offsetY, zlevel); cardCopy.transform.position = temp; int cardFaceId = i - (globalVars.cardFacesCount * (i / globalVars.cardFacesCount)); // int cardFaceId = deckModel.cards[i]; if (cardCount == rightAnswerPos) { if (App.Instance() != null) { App.Instance().setWantAnswer(cardFaceId, rightAnswerPos); } } Vector2 cardLocalScaleToUse = new Vector2(3.5f, 3.5f); cardCopy.transform.localScale = cardLocalScaleToUse; cardModel.setImg(temp, new Vector2(1, 1), App.Instance().getCardFace(cardFaceId)); cardModel.cardIndex = cardFaceId; //get cardModelSize: cardCount_x++; if (cardCount_x >= cardGrid_x) { cardCount_x = 0; cardCount_y++; } cardCount++; } }
public void ShowCards() { int cardCount = 0; foreach (int i in deck.GetCards()) { float co = cardOffset * cardCount; GameObject cardCopy = (GameObject)Instantiate(cardPrefab); Vector3 temp = start + new Vector3(co, 0f); cardCopy.transform.position = temp; CardModel cardModel = cardCopy.GetComponent <CardModel>(); cardModel.cardIndex = i; cardModel.ToggleFace(true); SpriteRenderer spriteRenderer = cardCopy.GetComponent <SpriteRenderer>(); spriteRenderer.sortingOrder = cardCount; cardCount++; } }