37 lines
718 B
C#
37 lines
718 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Billboard : MonoBehaviour
|
|
{
|
|
private Transform _parentObject;
|
|
public float heightOffset = 1.5f;
|
|
|
|
void Start()
|
|
{
|
|
_parentObject = transform.parent;
|
|
|
|
transform.SetParent(null);
|
|
}
|
|
|
|
void LateUpdate()
|
|
{
|
|
if (_parentObject == null) return;
|
|
|
|
if (Camera.main == null) return;
|
|
|
|
transform.position = _parentObject.position + Vector3.up * heightOffset;
|
|
|
|
transform.LookAt(Camera.main.transform);
|
|
transform.Rotate(0, 180, 0);
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
if (_parentObject == null)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|