Created
April 15, 2021 20:22
-
-
Save walterpalladino/0f077d186507d40cadccc8a89c55ff8d to your computer and use it in GitHub Desktop.
Unity 3D Billboard scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
//[ExecuteInEditMode] | |
public class CameraFacingBillboard : MonoBehaviour { | |
[SerializeField] | |
private Camera referenceCamera; | |
// Use this for initialization | |
void Start () { | |
if (!referenceCamera) { | |
referenceCamera = Camera.main; | |
} | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
//Orient the camera after all movement is completed this frame to avoid jittering | |
void LateUpdate() | |
{ | |
transform.LookAt(transform.position + referenceCamera.transform.rotation * Vector3.forward, referenceCamera.transform.rotation * Vector3.up); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment