IEnumerator Flip(Sprite startImage, Sprite endImage, int pieceIndex) { spriteRenderer.sprite = startImage; float time = 0f; while (time <= 1f) { float scale = scaleCurve.Evaluate(time); time = time + Time.deltaTime / duration; Vector3 localScale = transform.localScale; localScale.x = scale; transform.localScale = localScale; if (time >= 0.5f) { spriteRenderer.sprite = endImage; } yield return(new WaitForFixedUpdate()); } if (pieceIndex == -1) { pieceModel.ToggleFace(false); } else { pieceModel.pieceIndex = pieceIndex; pieceModel.ToggleFace(true); } }
void AddPiece(Vector3 position, int pieceIndex, int positionalIndex) { if (fetchedPieces.ContainsKey(pieceIndex)) { return; } GameObject pieceCopy = Instantiate(piecePrefab) as GameObject; pieceCopy.transform.position = position; PieceModel pieceModel = pieceCopy.GetComponent <PieceModel>(); pieceModel.pieceIndex = pieceIndex; pieceModel.ToggleFace(faceUp); switch (pieceIndex / 26) { case (0): pieceModel.color = "Red"; break; case (1): pieceModel.color = "Black"; break; case (2): pieceModel.color = "Green"; break; case (3): pieceModel.color = "Yellow"; break; default: pieceModel.color = "Joker"; break; } if (pieceModel.color == "Joker") { pieceModel.value = 20; } else { pieceModel.value = ((pieceIndex / 2) % 13) + 1; if (pieceModel.value == 0) { pieceModel.value = 13; } } SpriteRenderer spriteRenderer = pieceCopy.GetComponent <SpriteRenderer>(); spriteRenderer.sortingOrder = positionalIndex; fetchedPieces.Add(pieceIndex, pieceCopy); }