using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class DialogManagerBeforeRuins : MonoBehaviour { public GameObject NonCharacterParent; public Text boxTextObject; public GameObject audioSourceObject; public bool boxTextObjectShowing = false; public SensingBeforeRuins sensingScript; public string dialog0; public string dialog1; public string dialog2; public string dialog3; public string dialog4; public string dialog5; public string dialog6; public string floweybattle; private bool dialogOngoing = false; private string typed; private bool talkRunning = false; public GameObject floweyTalk; public GameObject floweyStand; public GameObject floweyGUITalk; public GameObject floweyGUIStand; public GameObject BlackScreen; public GameObject FriskUp; public GameObject FriskDown; public GameObject FriskLeft; public GameObject FriskRight; public GameObject Heart; public GameObject snd_test; public GameObject snd_battlefall; private float timeStart = 0; public Vector2 endPos; private Vector2 startPos; private int cycletracker = -1; private void managingFrisk(bool onoff) { if (onoff == false) { FriskDown.SetActive(false); FriskLeft.SetActive(false); FriskRight.SetActive(false); FriskUp.SetActive(false); } else if (onoff == true) { FriskDown.SetActive(true); FriskLeft.SetActive(true); FriskRight.SetActive(true); FriskUp.SetActive(true); } } IEnumerator talk() { talkRunning = true; if (floweyStand.activeInHierarchy) { floweyStand.SetActive(false); floweyTalk.SetActive(true); floweyGUIStand.SetActive(false); floweyGUITalk.SetActive(true); yield return new WaitForSeconds(0.125f); } else { floweyStand.SetActive(true); floweyTalk.SetActive(false); floweyGUIStand.SetActive(true); floweyGUITalk.SetActive(false); yield return new WaitForSeconds(0.125f); } talkRunning = false; } IEnumerator typeSentence(string sentence) { boxTextObject.text = ""; foreach (char letter in sentence.ToCharArray()) { if (letter.Equals('`')) { yield return new WaitForSeconds(0.25f); } else { audioSourceObject.GetComponent().Play(); boxTextObject.text += letter; typed += letter; yield return new WaitForSeconds(0.03f); audioSourceObject.GetComponent().Stop(); if (typed == sentence.Replace("`", "")) { dialogOngoing = false; typed = ""; } else { dialogOngoing = true; } } if (dialogOngoing) { if (!talkRunning) { StartCoroutine(talk()); } } else { StopCoroutine(talk()); floweyStand.SetActive(true); floweyTalk.SetActive(false); floweyGUIStand.SetActive(true); floweyGUITalk.SetActive(false); } } } private void heartTransistion() { } IEnumerator battletrans() { BlackScreen.SetActive(true); managingFrisk(false); Heart.SetActive(false); //play sound yield return new WaitForSeconds(0.075f); BlackScreen.SetActive(true); managingFrisk(true); Heart.SetActive(true); snd_test.GetComponent().Play(); yield return new WaitForSeconds(0.075f); snd_test.GetComponent().Stop(); BlackScreen.SetActive(true); managingFrisk(true); Heart.SetActive(false); yield return new WaitForSeconds(0.075f); BlackScreen.SetActive(true); managingFrisk(true); Heart.SetActive(true); snd_test.GetComponent().Play(); yield return new WaitForSeconds(0.075f); snd_test.GetComponent().Stop(); BlackScreen.SetActive(true); managingFrisk(true); Heart.SetActive(false); //play sound yield return new WaitForSeconds(0.075f); BlackScreen.SetActive(true); managingFrisk(false); Heart.SetActive(true); snd_battlefall.GetComponent().Play(); yield return new WaitForSeconds(0.5f); SceneManager.LoadScene(floweybattle); } // Start is called before the first frame update void Start() { dialog0 = dialog0.Replace("
", "\n"); dialog1 = dialog1.Replace("
", "\n"); dialog2 = dialog2.Replace("
", "\n"); dialog3 = dialog3.Replace("
", "\n"); dialog4 = dialog4.Replace("
", "\n"); dialog5 = dialog5.Replace("
", "\n"); dialog6 = dialog6.Replace("
", "\n"); } // Update is called once per frame void Update() { if (snd_battlefall.GetComponent().isPlaying) { if(timeStart == 0) { timeStart = Time.time; startPos = Heart.transform.position; } Heart.transform.position = Vector2.Lerp(startPos, endPos, Time.time - timeStart); } if ((sensingScript.contactingFloweyTrigger == true) && (cycletracker == -1)) { NonCharacterParent.SetActive(true); StartCoroutine(typeSentence(dialog0)); cycletracker = 0; boxTextObjectShowing = true; } if ((Input.GetKeyDown(KeyCode.Space)) && (!(dialogOngoing) && (cycletracker == 0))) { StopCoroutine(typeSentence(dialog0)); StartCoroutine(typeSentence(dialog1)); cycletracker = 1; boxTextObjectShowing = true; } else if ((Input.GetKeyDown(KeyCode.Space)) && (!(dialogOngoing) && (cycletracker == 1))) { StopCoroutine(typeSentence(dialog1)); StartCoroutine(typeSentence(dialog2)); cycletracker = 2; boxTextObjectShowing = true; } else if ((Input.GetKeyDown(KeyCode.Space)) && (!(dialogOngoing) && (cycletracker == 2))) { StopCoroutine(typeSentence(dialog2)); StartCoroutine(typeSentence(dialog3)); cycletracker = 3; boxTextObjectShowing = true; } else if ((Input.GetKeyDown(KeyCode.Space)) && (!(dialogOngoing) && (cycletracker == 3))) { StopCoroutine(typeSentence(dialog3)); StartCoroutine(typeSentence(dialog4)); cycletracker = 4; boxTextObjectShowing = true; } else if ((Input.GetKeyDown(KeyCode.Space)) && (!(dialogOngoing) && (cycletracker == 4))) { StopCoroutine(typeSentence(dialog4)); StartCoroutine(typeSentence(dialog5)); cycletracker = 5; boxTextObjectShowing = true; } else if ((Input.GetKeyDown(KeyCode.Space)) && (!(dialogOngoing) && (cycletracker == 5))) { StopCoroutine(typeSentence(dialog5)); StartCoroutine(typeSentence(dialog6)); cycletracker = 6; boxTextObjectShowing = true; } else if ((Input.GetKeyDown(KeyCode.Space)) && (!(dialogOngoing) && (cycletracker == 6))) { StopCoroutine(typeSentence(dialog6)); NonCharacterParent.SetActive(true); cycletracker = 7; boxTextObjectShowing = true; NonCharacterParent.SetActive(false); StartCoroutine(battletrans()); } } }