public IEnumerator Date (){ //while time is left int position = 0; int totalPoints = 0; bool quit = false; while (timeLeft > 0.0f) { int roundPoints = 0; points.text = "" +totalPoints; List<Word> selectedWords = new List<Word>(); Sentence s; do{ //pick the relevant sentence if (position >= sentences.Count) { position = 0; quit = true; } s = new Sentence(sentences[position]); position++; } while((s._affectionNeeded < totalPoints && s._comparison == "<" )||( s._affectionNeeded > totalPoints && s._comparison == ">")); if (quit) { break; } DateText.text = s.GetDateText(); ResponseText.text = s.GetPlayerResponse(); List<GameObject> wordsOnScreen = new List<GameObject>(); foreach (Word w in s._words) { GameObject newGO = GameObject.Instantiate (ClickableWord); newGO.transform.parent = canvas.transform; RectTransform rt = canvas.GetComponent<RectTransform> (); newGO.transform.localPosition = new Vector2 (Random.Range (-299.0f, -37.0f), Random.Range (-182.0f, 58.4f)); newGO.transform.localScale = Vector3.one; newGO.GetComponent<ClickableWord> ().init (w); wordsOnScreen.Add (newGO); } timeLeft -= Time.deltaTime; timerText.text = "" + (int)timeLeft; if (timeLeft <= 5.0f && timeRunningPlaying == false) { timeRunningPlaying = true; SoundManager.PlayTimeRunningOut (); } int sentencePosition = 0; bool confused = false; while (sentencePosition < s._slots.Count && timeLeft > 0.0f) { if (removeLastWord) { Word w = wordsAdded.Pop (); GameObject newGO = GameObject.Instantiate (ClickableWord); newGO.transform.parent = canvas.transform; RectTransform rt = canvas.GetComponent<RectTransform> (); newGO.transform.localPosition = new Vector2 (Random.Range (-350.0f, 350.0f), Random.Range (-250.0f, 250.0f)); newGO.transform.localScale = Vector3.one; newGO.GetComponent<ClickableWord> ().init (w); wordsOnScreen.Add (newGO); ResponseText.text.Replace (w._text, "_____"); sentencePosition--; } if (toAdd != null) { selectedWords.Add (toAdd); string curText = ResponseText.text; int posSpace = curText.IndexOf ("_____"); ResponseText.text = curText.Substring (0, posSpace) + " " + toAdd._text + " " + curText.Substring (posSpace + 5, curText.Length - posSpace-5); int pointsToAdd = 0; if (s._slots [sentencePosition] == toAdd._type) { pointsToAdd = toAdd._points; } else { pointsToAdd = -5; confused = true; } totalPoints += pointsToAdd; roundPoints = pointsToAdd; sentencePosition++; points.text = "" +totalPoints; toAdd = null; } timeLeft -= Time.deltaTime; timerText.text = "" + (int)timeLeft; if (timeLeft <= 5.0f && timeRunningPlaying == false) { timeRunningPlaying = true; SoundManager.PlayTimeRunningOut (); } yield return new WaitForEndOfFrame (); } if (confused) { DateImage.sprite = ConfusedReaction; responseText.text = s._confusedText; } else if (roundPoints < 0) { DateImage.sprite = BadReaction; responseText.text = s._badResponse; } else { DateImage.sprite = GoodReaction; responseText.text = s._goodResponse; } timeLeft -= Time.deltaTime; timerText.text = "" + (int)timeLeft; if (timeLeft <= 5.0f && timeRunningPlaying == false) { timeRunningPlaying = true; SoundManager.PlayTimeRunningOut (); } yield return new WaitForEndOfFrame (); foreach (GameObject w in wordsOnScreen) { if (w != null) { Destroy (w); } } } if (!quit) { //sentences were completed ResponseText.text = ""; responseText.text = ""; if (totalPoints < minConfusedAffection) { DateText.text = badDateText; } else { DateText.text = confusedDateText; } SoundManager.PlayNoNumber (); } else { //we ran out of time ResponseText.text = ""; responseText.text = ""; if (totalPoints < minConfusedAffection) { DateText.text = badDateText; SoundManager.PlayNoNumber (); } else if(totalPoints > minVictoryAffection){ DateText.text = goodDateText; SoundManager.PlayGotNumber (); PlayerPrefs.SetInt ("" + curScene, 1); } else { DateText.text = confusedDateText; } } yield return new WaitForSeconds (2.0f); SceneManager.LoadScene (0); }