5
4

More than 5 years have passed since last update.

TextMesh入りGameObjectのテキストがカメラに向かうようにする

Last updated at Posted at 2015-11-14

参考にしました。
http://spi8823.hatenablog.com/entry/2015/05/31/025903

TextMesh入りの GameObjectが作成されているという前提. GameObjectを置く位置によっては、テキストが明後日の方向に向いてしまうことがある。
カメラの方を向いてほしい。

transform.LookAt を使えとのこと!

using UnityEngine;
using System.Collections;

public class lookatcenter : MonoBehaviour {

    // Use this for initialization
    void Start () {
        GameObject MainCamera = GameObject.Find("MainCamera");
        Vector3 cameraPosition = new Vector3 (MainCamera.transform.position.x, MainCamera.transform.position.y, MainCamera.transform.position.z);

        transform.LookAt(cameraPosition);
    }

    // Update is called once per frame
    void Update () {

    }
}

中央を向く。という lookatcenter.cs を作成

Add Component -> Script でGameObjectに割り当てる
スクリーンショット 2015-11-14 15.39.08.png

できた。

5
4
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
5
4