Hello!
I am currently making an undertale like game, and I have some problems with the Dialogue.
For those of you who have never played undertale, basically the text writes itself out letter by letter, and then when you press a specific key(Usually either Enter or “Z”), it writes the next dialogue line.
And to add to it, if you press another button(Usually Shift or “X”) it writes it out all at once.
There’s also Icon changes but I don’t need help with those.
Basically, this is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Audio;
public class FlD : MonoBehaviour
{
Text txt;
string story;
int curentline = 0;
int texta = 0;
public Animator huh;
int a;
int m = 0;
public KeyCode ine;
public KeyCode fin;
public GameObject ime;
public Animator anie;
public int te = 1;
public int weee;
public int tele;
public GameObject y;
public int ret;
public int Q;
public float ag;
public int Bef;
public void Start()
{
ag = 0.09f;
Sraer();
ret = 2;
}
public void Sraer()
{
ime.SetActive(true);
txt = GetComponent<Text>();
story = txt.text;
txt.text = "";
StartCoroutine("PlayText");
}
public void Ruw()
{
if (Input.GetKeyDown(fin))
{
Bef = 9;
Debug.Log("aaa");
}
}
IEnumerator PlayText()
{
if (curentline == 0)
{
anie.SetFloat("Expression", 1);
//Here Im changing the sprite of the character
story ="Example one ";
}
if (curentline == 1)
{
anie.SetFloat("Talking", 0);
anie.SetFloat("Expression", 1);
if (anie.GetFloat("Expression") == 1) {
story = "Example 2, diffrent face";
}
//Here I'm Changing it again
}
foreach (char c in story)
{
if (Bef != 9)
{
texta++;
anie.SetFloat("Talking", 1);
txt.text += c;
yield return new WaitForSeconds(ag);
if (txt.text == story)
{
anie.SetFloat("Talking", 0);
yield return new WaitUntil(() => Input.GetKeyDown(ine));
txt.text = "";
curentline++;
a = 1;
StopAllCoroutines();
}
}
else if(Bef == 9){
StopAllCoroutines();
}
if (Input.GetKeyDown(fin))
{
txt.text = story;
break;
}
}
}
private void Update()
{
Ruw();
if (Input.GetKeyDown(fin))
{
ag = 0;
}
if (te == 1)
{
ime.SetActive(true);
Sraer();
te = 2;
}
if (a == 1 && Q == 2)
{
a = 0;
StartCoroutine("PlayText");
}
if (curentline > 2)
{
ime.SetActive(false);
}
if (curentline == 0)
{
weee = 4;
}
if (anie.GetFloat("Talking") == 1)
{
tele = 2;
//this value is used later on for changing the overworld sprite via another script
}
if (anie.GetFloat("Talking") == 0)
{
tele = 4;
//this value is used later on for changing the overworld sprite via another script
}
}
}
I know the code isn’t the cleanest, but I’m a beginner.
Anyhow, my problem is the fact that, while the letters do type out, it won’t type out the full Dialogue when I press the “fin” key(Currently set as “C”).
Any help is very much appreciated!
I’ve been struggling with this for a bit.
Thanks in Advance!