Skip to content

Instantly share code, notes, and snippets.

@bfollington
Created May 19, 2019 22:27
Show Gist options
  • Save bfollington/b8f500b71cdb4ce54d6a1d6d5df40628 to your computer and use it in GitHub Desktop.
Save bfollington/b8f500b71cdb4ce54d6a1d6d5df40628 to your computer and use it in GitHub Desktop.
A tiny MonoBehaviour for Unity3d that makes a sprite look at the camera
using UnityEngine;
using System.Collections;
public class FaceCamera : MonoBehaviour {
public bool LockX = false;
public bool LockY = false;
void Start () {
}
// Update is called once per frame
void LateUpdate () {
transform.rotation = Quaternion.Euler(
LockX ? 0 : Camera.main.transform.rotation.eulerAngles.x,
LockY ? 0 : Camera.main.transform.rotation.eulerAngles.y,
0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment