LoginSignup
10
6

More than 5 years have passed since last update.

キャラクター上にテキストを表示する

Posted at

キャラクター上に吹き出しっぽくテキストを表示する方法。uGUIを使う方法もあるようだけど、今回はTextMeshを使用。3Dオブジェクトとしてテキストを扱うことができるようです。

[手順]

  1. Create Emptyで空のオブジェクトを作成
  2. Mesh > TextMeshでTextMeshのコンポーネントを追加
  3. 文字を入れるとぼやけるのでfont sizeを上げるとはっきり
  4. 当然文字がデカくなるのでオブジェクト自体のScaleを調整

image.png
こんな感じ。

加えてスクリプトを追加して、点滅するようにしてみた。

C#
public class Callout : MonoBehaviour {

    private MeshRenderer textMesh; //MeshRendererのオンオフ用
    private bool is_Active = true; //テキストの点滅繰り返し用

    // Use this for initialization
    void Start () {
        textMesh = GetComponent<MeshRenderer>(); //MeshRendererを取得
        StartCoroutine("Blink"); //コルーチンでBlink関数を呼び出し
    }

    IEnumerator Blink()
    {
        while (is_Active) //Trueの間
        {
            textMesh.enabled = false; //MeshRendererのオフ
            yield return new WaitForSeconds(0.5f); //0.5秒待って
            textMesh.enabled = true; //MeshRendererのオン
            yield return new WaitForSeconds(0.5f); //0.5秒待って
        }
    }
}

結果はこんな感じ。

20171113_01.gif
以上。

10
6
2

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
10
6