You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
796 B
C#

3 years ago
using UnityEngine;
using System.Collections;
public class Billboard : MonoBehaviour
{
public Camera Camera;
public bool Active = true;
public bool AutoInitCamera = true;
private GameObject myContainer;
private Transform t, camT, contT;
private void Awake()
{
if (AutoInitCamera) {
Camera = Camera.main;
Active = true;
}
t = transform;
camT = Camera.transform;
var parent = t.parent;
myContainer = new GameObject { name = "Billboard_" + t.gameObject.name };
contT = myContainer.transform;
contT.position = t.position;
t.parent = myContainer.transform;
contT.parent = parent;
}
private void Update()
{
if (Active)
contT.LookAt(contT.position + camT.rotation * Vector3.back, camT.rotation * Vector3.up);
}
}