/////////////////////////////////////////////////////////////////////// /// Game Logic /////////////////////////////////////////////////////////////////////// // check card interaction with pointer private void GameInteraction() { GameObject selectedCard = null; // assign left and right controllers interaction use if (mainHandIU == null) { if (controllerHand == 0 && GameObject.Find("LeftControllerAlias") != null) { mainHandIU = GameObject.Find("LeftControllerAlias").GetComponent <VRTK_InteractUse>(); } else if (controllerHand == 1 && GameObject.Find("RightControllerAlias") != null) { mainHandIU = GameObject.Find("RightControllerAlias").GetComponent <VRTK_InteractUse>(); } } if (mainHandIU.GetUsingObject() != null && !IsCardRotating(mainHandIU.GetUsingObject())) { selectedCard = mainHandIU.GetUsingObject(); if (!IsCardFlipped(selectedCard)) // not flipped { selectedCards.Add(selectedCard); selectedCard.GetComponent <Card>().flipped = true; StartCoroutine(Rotate(selectedCard.transform, new Vector3(0, 180, 0), 0.5f)); SetCardsColor(selectedCard.transform, Color.white); } //else //{ // flipped // selectedCards.Remove(selectedCard); // selectedCard.GetComponent<Card>().flipped = false; // StartCoroutine(Rotate(selectedCard.transform, new Vector3(0, 180, 0), 1f)); // SetCardsColor(selectedCard.transform, Color.black); //} } }
/////////////////////////////////////////////////////////////////////// /// Game Logic /////////////////////////////////////////////////////////////////////// // check card interaction with pointer (Pair game) private void PairGameInteraction() { // assign left and right controllers interaction use if (leftIU == null) { if (GameObject.Find("LeftControllerAlias") != null) { leftIU = GameObject.Find("LeftControllerAlias").GetComponent <VRTK_InteractUse>(); } } if (rightIU == null) { if (GameObject.Find("RightControllerAlias") != null) { rightIU = GameObject.Find("RightControllerAlias").GetComponent <VRTK_InteractUse>(); } } // assign first and second cards when used by the controller if (firstCard == null) { if (leftIU.GetUsingObject() != null) { if (leftIU.GetUsingObject() != oldFirstCard && leftIU.GetUsingObject() != oldSecondCard) { if (oldFirstCard != null && oldSecondCard != null) { // delay rotation for old two cards StartCoroutine(Rotate(oldFirstCard.transform, new Vector3(0, 180, 0), 1f, false)); StartCoroutine(Rotate(oldSecondCard.transform, new Vector3(0, 180, 0), 1f, false)); } firstCard = leftIU.GetUsingObject(); StartCoroutine(Rotate(firstCard.transform, new Vector3(0, 180, 0), 0.5f, true)); } else { if (leftIU.GetUsingObject() == oldFirstCard) { StartCoroutine(Rotate(oldSecondCard.transform, new Vector3(0, 180, 0), 1f, false)); } else if (leftIU.GetUsingObject() == oldSecondCard) { StartCoroutine(Rotate(oldFirstCard.transform, new Vector3(0, 180, 0), 1f, false)); } firstCard = leftIU.GetUsingObject(); } } else if (rightIU.GetUsingObject() != null) { if (rightIU.GetUsingObject() != oldFirstCard && rightIU.GetUsingObject() != oldSecondCard) { if (oldFirstCard != null && oldSecondCard != null) { // delay rotation for old two cards StartCoroutine(Rotate(oldFirstCard.transform, new Vector3(0, 180, 0), 1f, false)); StartCoroutine(Rotate(oldSecondCard.transform, new Vector3(0, 180, 0), 1f, false)); } firstCard = rightIU.GetUsingObject(); StartCoroutine(Rotate(firstCard.transform, new Vector3(0, 180, 0), 0.5f, true)); } else { if (rightIU.GetUsingObject() == oldFirstCard) { StartCoroutine(Rotate(oldSecondCard.transform, new Vector3(0, 180, 0), 1f, false)); } else if (rightIU.GetUsingObject() == oldSecondCard) { StartCoroutine(Rotate(oldFirstCard.transform, new Vector3(0, 180, 0), 1f, false)); } firstCard = rightIU.GetUsingObject(); } } } else if (firstCard != null && secondCard == null) { if (leftIU.GetUsingObject() != null && leftIU.GetUsingObject() != firstCard) { secondCard = leftIU.GetUsingObject(); StartCoroutine(Rotate(secondCard.transform, new Vector3(0, 180, 0), 0.5f, true)); } else if (rightIU.GetUsingObject() != null && rightIU.GetUsingObject() != firstCard) { secondCard = rightIU.GetUsingObject(); StartCoroutine(Rotate(secondCard.transform, new Vector3(0, 180, 0), 0.5f, true)); } } // main game logic to check if the text is the same if (firstCard != null && secondCard != null) { if (firstCard.GetComponent <Card>().flipped&& secondCard.GetComponent <Card>().flipped) { // if odd item, remove interactable ability if (firstCard == oddItem) { firstCard.GetComponent <VRTK_InteractableObject>().isUsable = false; firstCard = null; StartCoroutine(Rotate(secondCard.transform, new Vector3(0, 180, 0), 1f, false)); secondCard = null; } else if (secondCard == oddItem) { secondCard.GetComponent <VRTK_InteractableObject>().isUsable = false; secondCard = null; StartCoroutine(Rotate(firstCard.transform, new Vector3(0, 180, 0), 1f, false)); firstCard = null; } else { if (gameData == GameData.Letter) { if (firstCard.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <TextMeshProUGUI>().text == secondCard.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <TextMeshProUGUI>().text) { oldFirstCard = null; oldSecondCard = null; firstCard.GetComponent <VRTK_InteractableObject>().isUsable = false; secondCard.GetComponent <VRTK_InteractableObject>().isUsable = false; firstCard = null; secondCard = null; completedPair++; } else { oldFirstCard = firstCard; oldSecondCard = secondCard; firstCard = null; secondCard = null; } } else if (gameData == GameData.Shape) { Sprite fstSprite = firstCard.transform.GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetComponent <Image>().sprite; Sprite secSprite = secondCard.transform.GetChild(0).GetChild(0).GetChild(1).GetChild(0).GetComponent <Image>().sprite; if (fstSprite != null && secSprite != null && fstSprite == secSprite) { oldFirstCard = null; oldSecondCard = null; firstCard.GetComponent <VRTK_InteractableObject>().isUsable = false; secondCard.GetComponent <VRTK_InteractableObject>().isUsable = false; firstCard = null; secondCard = null; completedPair++; } else { oldFirstCard = firstCard; oldSecondCard = secondCard; firstCard = null; secondCard = null; } } } CheckPairCompletion(); } } }