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.
32 lines
618 B
C#
32 lines
618 B
C#
1 month ago
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class Billboard : MonoBehaviour
|
||
|
{
|
||
|
private Transform cam;
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
Camera mainCam = Camera.main;
|
||
|
|
||
|
if (mainCam != null)
|
||
|
{
|
||
|
cam = mainCam.transform;
|
||
|
|
||
|
// Auto-assign Event Camera at runtime (fixes prefab reference issue)
|
||
|
Canvas canvas = GetComponent<Canvas>();
|
||
|
if (canvas != null)
|
||
|
{
|
||
|
canvas.worldCamera = mainCam;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void LateUpdate()
|
||
|
{
|
||
|
if (cam == null) return;
|
||
|
|
||
|
transform.forward = cam.forward;
|
||
|
}
|
||
|
}
|