Skip to content

Instantly share code, notes, and snippets.

View brihernandez's full-sized avatar

Brian Hernandez brihernandez

View GitHub Profile
@brihernandez
brihernandez / UGUIButtonExtensions.cs
Last active January 18, 2021 18:21
Set the text of a button in a more convenient and lazy way.
using UnityEngine.UI;
public static class UGUIButtonExtensions
{
public static void SetTextTMPro(this Button button, string text)
{
button.GetComponentInChildren<TMPro.TextMeshProUGUI>().text = text;
}
public static void SetTextUGUI(this Button button, string text)
@brihernandez
brihernandez / RevealTextWithDelay.cs
Last active January 9, 2021 16:07
Extension method to reveal TextMeshPro characters over time. Requires UniTask.
using System.Collections.Generic;
using System.Threading;
using Cysharp.Threading.Tasks;
using TMPro;
public static class TextMeshProExtensions
{
private static Dictionary<TextMeshProUGUI, CancellationTokenSource> textToCancel = new Dictionary<TextMeshProUGUI, CancellationTokenSource>();
@brihernandez
brihernandez / LayerIDs.cs
Last active November 10, 2023 00:54
Simple wrapper classes for handling layer related operations in Unity.
using UnityEngine;
/// <summary>
/// Convenience class for handling layer related operations and lookups in Unity.
/// </summary>
public readonly struct UnityLayer
{
/// <summary>
/// Name of the layer as defined in the Tags and Layers window in Unity.
/// </summary>
@brihernandez
brihernandez / PID.cs
Last active October 27, 2022 05:01
I've been using this PID controller code for years.
using UnityEngine;
// From http://forum.unity3d.com/threads/68390-PID-controller
// Thank you andeeeee
public class PID
{
public float pFactor, iFactor, dFactor;
float integral;
float lastError;
@brihernandez
brihernandez / FloatingOrigin.cs
Last active June 3, 2025 17:58
Floating origin to handle large worlds in Unity.
// Based on the Unity Wiki FloatingOrigin script by Peter Stirling
// URL: http://wiki.unity3d.com/index.php/Floating_Origin
using UnityEngine;
using UnityEngine.SceneManagement;
public class FloatingOrigin : MonoBehaviour
{
[Tooltip("Point of reference from which to check the distance to origin.")]
public Transform ReferenceObject = null;