I am trying to make a button slowly appear after the coroutine, TypeLine, has finished. Am I better off coding, or creating an animation to do this? Here is the code I have so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class IntroLines : MonoBehaviour
{
public TextMeshProUGUI textComponent;
public string[] BeginningLines;
public float textSpeed;
private int index;
public Button IntroButton1;
void Start()
{
Button btn1 = IntroButton1.GetComponent<Button>();
btn1.onClick.AddListener(DisplayNextLine);
textComponent.text = string.Empty;
startIntroLines();
}
void DisplayNextLine()
{
if(textComponent.text == BeginningLines[index])
{
NextIntroLine();
}
else
{
StopAllCoroutines();
textComponent.text = BeginningLines[index];
}
}
void startIntroLines()
{
index = 0;
StartCoroutine(TypeLine());
}
IEnumerator TypeLine()
{
foreach (char c in BeginningLines[index].ToCharArray())
{
textComponent.text += c;
yield return new WaitForSeconds (textSpeed);
}
}
void NextIntroLine()
{
if (index < BeginningLines.Length - 1)
{
index++;
textComponent.text = string.Empty;
StartCoroutine(TypeLine());
}
else
{
//gameObject.SetActive(false);
}
}
}