public void CardTwoButton() { print("Using Card Two, adding timer"); Debug.Log("Card Two action: " + CardTwo.MyWork.Method.ToString()); CardTwo.MyWork(); DisableAllCards(); }
//Checks if two cards match private void DoTheyMatch() { if (cardOne == cardTwo) { //Reseting the two cards id cardOne = -1; cardTwo = -2; isPressed = false; //When two cards are matched //we remove them from the grid //NOTE: we do not disable the entire obect because since these //objects are put onto a grid, it shifts everything over when its SetActive(false) CardOne.GetComponent <Image>().enabled = false; CardTwo.GetComponent <Image>().enabled = false; CardOne.transform.GetChild(0).gameObject.SetActive(false); CardTwo.transform.GetChild(0).gameObject.SetActive(false); //Set the two GO reference of the 2 cards back to null CardOne = null; CardTwo = null; cardsMatched++; //keeps track of # of total cards matched //Checks if you have won(matched all cards) if (cardsMatched == PlayerData.numOfCards) { //Stop timer and store into a static variable from a static script/class timer.Stop(); PlayerData.gameTime = (timer.ElapsedMilliseconds / 1000f); PlayerData.gameScore = score; //Load the end game scene SceneManager.LoadScene("WinLose"); } } else //If mis matched cards... { //re-enables the cards to be clickable (since a fail matched occur) CardOne.GetComponent <Button>().enabled = true; CardTwo.GetComponent <Button>().enabled = true; //Sets the front side of the card to unactive(hide the image) CardOne.transform.GetChild(0).gameObject.SetActive(false); CardTwo.transform.GetChild(0).gameObject.SetActive(false); //Reset checking values cardOne = -1; cardTwo = -2; CardOne = null; CardTwo = null; isPressed = false; //Update the score on the screen score = score - 40; //Deduct 40 points for mismatch scoreText.text = score.ToString(); //Show on current points onto screen } //This is used to check if the player has lost all points and therefore lost the game if (score == 0) { //Stop timer and store into a static variable from a static script/class timer.Stop(); PlayerData.gameTime = (timer.ElapsedMilliseconds / 1000f); PlayerData.gameScore = score; SceneManager.LoadScene("WinLose"); } isPressed = true; }