private void BtnContinuePressed() { if (CardType.Get() == CardType.Type.Genetics) { _pileCardId = CardOutcomes.Genetic.OutcomesReceivedCount - 1; _pileCard = CardOutcomes.Genetic.Pile.Get()[_pileCardId]; } else { _pileCardId = CardOutcomes.Environment.OutcomesReceivedCount - 1; _pileCard = CardOutcomes.Environment.Pile.Get()[_pileCardId]; } //stop the current coroutines and move the card into the pile card position Transform pileCardT = _pileCard.transform; StopAllCoroutines(); StartCoroutine(LerpCardTransform(gameObject, pileCardT.position, pileCardT.localScale, pileCardT.rotation, 1.0f)); }
private void Start() { //determine whether the player guessed correctly if ((Guess.Higher && Guess.NewCardHigher) || (Guess.Higher == false && Guess.NewCardHigher == false)) { Guess.Correct = true; } else { Guess.Correct = false; } GameObject btnContinueGo = transform.Find("btnContinue").gameObject; btnContinue = btnContinueGo.GetComponent <Button>(); btnContinue.onClick.AddListener(BtnContinuePressed); List <Card> cards; btnContinue = btnContinueGo.GetComponent <Button>(); TextMeshProUGUI txtHeading = transform.Find("txtHeading").GetComponent <TextMeshProUGUI>(); TextMeshProUGUI txtSubHeading = transform.Find("txtSubHeading").GetComponent <TextMeshProUGUI>(); //depending on whether the player chose correctly, display the correct outcome if (Guess.Correct) { //retrieve a list of all good outcomes if (CardType.Get() == CardType.Type.Genetics) { cards = CardOutcomes.Get().GeneticCards.GoodCards; } else { cards = CardOutcomes.Get().EnvironmentCards.GoodCards; } GetComponent <Image>().color = positivePrimaryColour; btnContinueGo.GetComponent <Image>().color = positiveSecondaryColour; txtHeading.text = "Good Choice!"; txtSubHeading.text = "You Receive a good " + CardType.Get() + " card."; } else { //retrieve a list of all bad outcomes if (CardType.Get() == CardType.Type.Genetics) { cards = CardOutcomes.Get().GeneticCards.BadCards; } else { cards = CardOutcomes.Get().EnvironmentCards.BadCards; } GetComponent <Image>().color = negativePrimaryColour; btnContinueGo.GetComponent <Image>().color = negativeSecondaryColour; txtHeading.text = "Bad Choice"; txtSubHeading.text = "You Receive a bad " + CardType.Get() + " card."; } //choose an outcome card for the player Card newCard = cards[Random.Range(0, cards.Count)]; newCard.IsPositive = Guess.Correct; //store the new card if (CardType.Get() == CardType.Type.Genetics) { CardOutcomes.Genetic.Add(newCard); } else { CardOutcomes.Environment.Add(newCard); } //set the spawn position of the popup and move it to the centre of the screen transform.localPosition = new Vector3(0.0f, -1500.0f, 0.0f); StartCoroutine(LerpCardY(gameObject, 0.0f, 2.0f)); }
//private float _lerpTimer; //private bool _btnPressed; //private Vector3 _cardRestPos = Vector3.zero; //private int outcomeType = -1; //-1 = undefined, 0 = negative, 1 = positive // Start is called before the first frame update private void Start() { Card card = null; if (CardType.Get() == CardType.Type.Genetics) { _cardId = CardOutcomes.Genetic.OutcomesReceivedCount - CardOutcomes.Genetic.Pile.OutcomesViewed; CardOutcomes.Genetic.Pile.OutcomesViewed++; _pileCard = CardOutcomes.Genetic.Pile.Get()[_cardId]; card = CardOutcomes.Genetic.Received()[_cardId]; //add the points from the outcome to the new genetic total Points.Genetic.Increment(card.Points); } else { _cardId = CardOutcomes.Environment.OutcomesReceivedCount - CardOutcomes.Environment.Pile.OutcomesViewed; CardOutcomes.Environment.Pile.OutcomesViewed++; _pileCard = CardOutcomes.Environment.Pile.Get()[_cardId]; card = CardOutcomes.Environment.Received()[_cardId]; //add the points from the outcome to the new environment total Points.Environment.Increment(card.Points); } _cardPileHandler = _pileCard.transform.parent.parent.GetComponent <CardPileHandler>(); //set the initial position to that of the card on the pile transform.position = _pileCard.transform.position; transform.localScale = _pileCard.transform.localScale; transform.rotation = _pileCard.transform.rotation; _pileCard.SetActive(false); Image bgMain = GetComponent <Image>(); //begin by setting the graphics colours depending on whether the outcome was positive or negative //Image bgMain = transform.Find("bgMain").GetComponent<Image>(); //Image bottomPanel = bgMain.transform.Find("bottomPanel").GetComponent<Image>(); Image btnContinueBackground = transform.Find("btnContinue").GetComponent <Image>(); //get references to all the text boxes TextMeshProUGUI txtHeading = transform.Find("txtHeading").GetComponent <TextMeshProUGUI>(); TextMeshProUGUI txtSubHeading = transform.Find("txtSubHeading").GetComponent <TextMeshProUGUI>(); TextMeshProUGUI txtBody = transform.Find("txtBody").GetComponent <TextMeshProUGUI>(); TextMeshProUGUI txtPoints = transform.Find("txtPoints").GetComponent <TextMeshProUGUI>(); string pointsPrefix = ""; //determine whether the player has received a positive or negative outcome if (card.IsPositive) { //set the popup panel colours bgMain.color = positivePrimaryColour; //bottomPanel.color = positiveSecondaryColour; btnContinueBackground.color = positiveButtonColour; pointsPrefix = "+"; } else { //set the popup panel colours bgMain.color = negativePrimaryColour; //bottomPanel.color = negativeSecondaryColour; btnContinueBackground.color = negativeButtonColour; } //populate the outcome text with the data from the JSON files txtHeading.text = card.Heading; txtSubHeading.text = card.SubHeading; txtBody.text = card.Description; txtPoints.text = pointsPrefix + card.Points + " Points"; //display the card pile card, and update the position of the text overlay if (_cardId < 4) { _cardPileHandler.EnableCard(_cardId + 1, true); } _cardPileHandler.UpdateCardText(true, (_cardId == 4) ? 3 : 4); //find the GUI Handler class and update the GUI //GameObject.Find("MainGUI").GetComponent<GUIHandler>().UpdateTxtPoints(); _btnContinue = transform.Find("btnContinue").GetComponent <Button>(); _btnContinue.onClick.AddListener(BtnContinuePressed); //lerp the card to the middle of the screen StartCoroutine(LerpCardTransform(gameObject, new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.7f, 0.7f, 0.7f), Quaternion.identity, 1.0f, false)); }