Печатающий текст при нажатии на кнопку

Рейтинг: -3Ответов: 1Опубликовано: 11.04.2023
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TextOne : MonoBehaviour
{
    public Text TextGameObject;
    private string text;

    private void Start()
    {
        text = TextGameObject.text;
        TextGameObject.text = "";
        StartCoroutine(TextCorutine());
    }


    IEnumerator TextCorutine()
    {
        foreach (char abc in text)
        {
            TextGameObject.text += abc;
            yield return new WaitForSeconds(0.05f);
        }
    }
}

Как сделать что бы в unity при нажатии печатался текст, а не тогда когда запускаешь unity

Ответы

▲ 0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TextOne : MonoBehaviour
{
    public Text TextGameObject;
    private string text;

    public void OneText()
    {
        text = TextGameObject.text;
        TextGameObject.text = "";
        StartCoroutine(TextCorutine());
    }


    IEnumerator TextCorutine()
    {
        foreach (char abc in text)
        {
            TextGameObject.text += abc;
            yield return new WaitForSeconds(0.05f);
        }
    }
}