ZoeAppClass/Assets/Jogos/275/Scripts/SchGame_Speach.cs

132 lines
3.4 KiB
C#

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<string> days = new List<string>();
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<Image> imgs = new List<Image>() {
GameObject.Find("CharacterHead").GetComponent<Image>(),
GameObject.Find("CharacterArm").GetComponent<Image>(),
GameObject.Find("CharacterArmRight").GetComponent<Image>(),
GameObject.Find("CharacterBody").GetComponent<Image>()
};
List<CanvasGroup> imgsOut = new List<CanvasGroup>() {
GameObject.Find("OptionsDrop").GetComponent<CanvasGroup>(),
GameObject.Find("Options").GetComponent<CanvasGroup>()
};
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<GameControl>();
jooj.finishedGame = true;
}
IEnumerator WriteText(string writeSpeach)
{
Text txtSpeach = GetComponent<Text>();
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;
}
}