What I have now is a script that animates text, and a public array that stores all text in the scene.
What I need help with is finding a way to display only specific text when you click on a gameobject.
Eg. I want to click on the boltcutters, then display only boltcutter specific text, then close the UI textbox.
The way the script is set up now is really hard to do, I've tried to make a public array then have the main script inherit from the public array but that doesn't work.
Main Script:
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.EventSystems;
public class typewriteeffect : MonoBehaviour
{
[SerializeField] TextMeshProUGUI typewriterEffect;
[SerializeField] float timeBetweenCharacters;
[SerializeField] float timeBetweenWords;
public string[] stringArray;
int i = 0;
void Start()
{
EndCheck();
}
public void EndCheck()
{
if(i<= stringArray.Length -1)
{
typewriterEffect.text = stringArray[i];
StartCoroutine(TextVisible());
}
}
private IEnumerator TextVisible()
{
typewriterEffect.ForceMeshUpdate();
int totalVisibleCharacters = typewriterEffect.textInfo.characterCount;
int counter = 0;
while (true)
{
int visibleCount = counter % (totalVisibleCharacters + 1);
typewriterEffect.maxVisibleCharacters = visibleCount;
if (visibleCount >= totalVisibleCharacters)
{
//Invoke("EndCheck", timeBetweenWords);
i += 1;
break;
}
counter += 1;
yield return new WaitForSeconds(timeBetweenCharacters);
}
}
}