Unity公告板的使用:
公告板技术是3D游戏中用的非常多的一种技术,主要是用于控制场景中的Texture的方向,让他始终以一定的角度对着我们的镜头(一般是垂直于镜头)。
/----------------------------------------------------------------
// description:公告板组件,用于让对象始终朝向摄像机
// DateTime: 2014/4/25 10:03:56
//----------------------------------------------------------------
using UnityEngine;
using System.Collections;
public class BillBoard : MonoBehaviour
{
public Camera camera;
Quaternion direction = new Quaternion();
// Use this for initialization
void Start()
{
direction.x = transform.localRotation.x;
direction.y = transform.localRotation.y;
direction.z = transform.localRotation.z;
direction.w = transform.localRotation.w;
}
// Update is called once per frame
void Update()
{
Camera cam = null;
if (camera != null)
{
cam = camera;
}
else
{
cam = Camera.main;
if (!cam)
return;
}
transform.rotation = cam.transform.rotation * direction;
}
}