here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class StoryManager : MonoBehaviour
{
public Text[] convos;
public Button next;
private int currentConvo = 0;
public float delay;
private bool endOfPage = false;
private bool endOfConvo = false;
// Start is called before the first frame update
void Start()
{
endOfPage = false;
endOfConvo = false;
ChangeText();
}
public void ChangeText()
{
Debug.Log("current convo at the start " + currentConvo);
Type();
if(currentConvo == convos.Length - 1)
{
endOfPage = true;
}
if(endOfPage)
{
next.gameObject.SetActive(false);
}
currentConvo++;
Debug.Log("current convo at the end " + currentConvo);
}
public void Type()
{
StartCoroutine(Typewriter());
}
IEnumerator Typewriter()
{
for(int i = 0; i <= convos[currentConvo].text.Length; i++)
{
Debug.Log("current convo during type " + currentConvo);
GetComponent<Text>().text = convos[currentConvo].text.Substring(0,i);
yield return new WaitForSeconds(delay);
Debug.Log("here");
if(i == convos[currentConvo].text.Length)
{
endOfConvo = true;
Debug.Log("and here");
}
}
}
public void NextConvo()
{
if(!endOfConvo)
{
StopCoroutine(Typewriter());
GetComponent<Text>().text = convos[currentConvo].text;
endOfConvo = true;
}
if(endOfConvo)
{
currentConvo++;
ChangeText();
}
}
}
for some reason, when the method is called and runs down to the typewriter coroutine, it debugs that it enters with currentconvo as 0, but doesn’t debug here, or the next debug, and here. Instead, it goes straight into the following currentconvo, and begins to typewrite out the second paragraph instead. THAT coroutine does it letter by letter, and debugs all the way through, then stops like it should. I cannot figure out why it doesn’t even remotely START typing out the first paragraph, and instead skips to the next. Also, when I hooked NextConvo() up to a button, and pressed it, it skipped the third paragraph in the same way as it does the first, then displays the forth paragraph. Any help welcome.