Skip to content

Instantly share code, notes, and snippets.

@VoQn
Created April 30, 2013 10:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VoQn/5487908 to your computer and use it in GitHub Desktop.
Save VoQn/5487908 to your computer and use it in GitHub Desktop.
Unity3D でよくやる平面ビルボード 使い方は readme.md にて

使い方

  • 床面に平行な plane mesh を持つ GameObject を作る
  • Billboard.cs をコンポーネントに追加
  • 常時向けさせたいカメラを D&D でインスペクタから指定
    • 指定していない場合且つ isAutoFace にチェックが入っていた場合、MainCamera タグのついた GameObject に対して自動的に向くようになる
    • 指定せず、かつ isAutoFace にチェックが入っていない場合、床に置かれっぱなしのようにレンダリングされるので注意

応用

  • 描画レイヤーを ユーザー定義の "Sprite2D" とかにする
  • MainCamera のヒエラルキーの下に ↑ で定義した描画レイヤーのみレンダリングするカメラを用意する
    • depth は MainCamera よりも前に
  • MainCamera の描画レイヤーから ↑ のレイヤーはレンダリングから外す
using UnityEngine;
public class BillBoard : MonoBehaviour {
public Transform targetToFace;
public bool isAutoFace = true;
Quaternion adjustEuler = Quaternion.Euler (90, 180, 0);
// Use this for initialization
void Start ()
{
if (targetToFace == null && isAutoFace) {
var mainCameraObject = GameObject.FindGameObjectWithTag("MainCamera");
targetToFace = mainCameraObject.transform;
}
}
// Update is called once per frame
void Update ()
{
if (targetToFace != null) {
transform.rotation = targetToFace.rotation;
transform.rotation *= adjustEuler;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment