代码语言:javascript复制
using UnityEngine;
using System.Collections;
public class LookAtCam : MonoBehaviour {
public Transform m_camTrans;
// Use this for initialization
void Start () {
}
void Update()
{
Vector3 relativePos = transform.position - m_camTrans.position;
Quaternion lookAtRotation = Quaternion.LookRotation(relativePos, Vector3.up);
this.transform.rotation = Quaternion.Lerp(this.transform.rotation, lookAtRotation, Time.deltaTime);
}
}
非插值
代码语言:javascript复制public class BEBillboard3D : MonoBehaviour {
public bool UsePosition = false;
Camera cam;
void Start() {
cam = Camera.main;
}
void Update() {
if(UsePosition) {
Vector3 vDir = cam.transform.position - transform.position;
vDir.Normalize();
transform.rotation = Quaternion.LookRotation(-vDir);
}
else {
transform.rotation = cam.transform.rotation;
}
}
}