using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SchGame_Speach : MonoBehaviour { public string monday, tuesday, wednesday, thursday, friday; public static SchGame_Speach instance; public GameObject objFinish; private void Awake() { instance = this; objFinish = GameObject.Find("FinishClass"); objFinish.SetActive(false); GameControl.instance.StartedGame(); } public void RefreshText() { List days = new List(); days.AddRange(new string[5] { monday, tuesday, wednesday, thursday, friday }); bool complete = true; for (int i = 0; i < days.Count; i++) { if (days[i].Length == 0) { complete = false; days[i] = "_____"; } else { days[i] = days[i][0].ToString().ToUpper() + days[i].ToString(); days[i] = days[i].Remove(1,1); Debug.Log(days[i]); } } StartCoroutine(WriteText("On Monday I have " + days[0] + " , on Tuesday I have " + days[1] + " . Wednesday " + "is when I have " + days[2] + " , Thursday, " + days[3] + " and on Friday I have " + days[4] + " .")); if (!complete) { return; } StartCoroutine(EndGame()); } IEnumerator EndGame() { List imgs = new List() { GameObject.Find("CharacterHead").GetComponent(), GameObject.Find("CharacterArm").GetComponent(), GameObject.Find("CharacterArmRight").GetComponent(), GameObject.Find("CharacterBody").GetComponent() }; List imgsOut = new List() { GameObject.Find("OptionsDrop").GetComponent(), GameObject.Find("Options").GetComponent() }; float value = 1; while (value > 0) { value -= Time.deltaTime * 2; foreach (var item in imgsOut) { item.alpha = value; } yield return new WaitForEndOfFrame(); } foreach (var item in imgsOut) { item.alpha = 0; } while (value < 1) { value += Time.deltaTime * 2; foreach (var item in imgs) { item.color = new Color(1, 1, 1, value); } yield return new WaitForEndOfFrame(); } foreach (var item in imgs) { item.color = new Color(1, 1, 1, value); } yield return new WaitForSecondsRealtime(2); objFinish.SetActive(true); yield break; } public void FinishGame() { GameControl jooj = GameObject.Find("GameControl").GetComponent(); jooj.finishedGame = true; } IEnumerator WriteText(string writeSpeach) { Text txtSpeach = GetComponent(); for (int i = 0; i < writeSpeach.Length; i++) { string thisTxt = writeSpeach; thisTxt = thisTxt.Remove(i); txtSpeach.text = thisTxt; yield return new WaitForSecondsRealtime(.005f); } txtSpeach.text = writeSpeach; } }