0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Unity】テキストを1文字ずつ表示する方法

Posted at

Unityを使ったゲーム開発において、テキスト表示は重要な要素の一つです。
しかし、一度に全てのテキストを表示すると、プレイヤーにとって読みづらいので
1文字ずつ表示するコードのメモです。

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

public class TextDisplay : MonoBehaviour
{
    public float displaySpeed = 0.1f; // 1文字の表示速度

    private Text textComponent;
    private string displayText;

    void Start()
    {
        textComponent = GetComponent<Text>();
        displayText = textComponent.text;
        textComponent.text = ""; // テキストを初期化
        StartCoroutine(DisplayText());
    }

    IEnumerator DisplayText()
    {
        foreach (char c in displayText)
        {
            textComponent.text += c;
            yield return new WaitForSeconds(displaySpeed);
        }
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?