Skip to content

Instantly share code, notes, and snippets.

@yanniboi
Created May 28, 2021 19:42
Show Gist options
  • Save yanniboi/4502e9c9aecac1eb7874a1a0c4eceebb to your computer and use it in GitHub Desktop.
Save yanniboi/4502e9c9aecac1eb7874a1a0c4eceebb to your computer and use it in GitHub Desktop.
Displays text at certain zoom level in Unity Editor. By Alex Strook (https://twitter.com/AlexStrook/status/1398304186505236487)
using UnityEditor;
using UnityEditor.SceneManagement;
public class EditorValueDisplay : MonoBehaviour
{
public string const = "0000";
private float _visibilityDistance = 2.5;
private float _worldOffset = 0.1f;
public void OnDrawGizmos()
{
if (Vector3.Distance(transform.position, SceneView.currentDrawingSceneView.camera.transform.position) < _visibilityDistance)
{
GUIStyle style = new GUIStyle();
style.fontStyle = FontStyle.Bold;
style.fontSize = 20;
style.normal.textColor = Color.magenta;
Handles.Label(transform.position + new Vector3(0, _worldOffset, 0), code, style);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment