Skip to content

Instantly share code, notes, and snippets.

@pinkas
Created February 26, 2019 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinkas/b2f63084375a5a16e88c8d4df68972bd to your computer and use it in GitHub Desktop.
Save pinkas/b2f63084375a5a16e88c8d4df68972bd to your computer and use it in GitHub Desktop.
The class name should self explanatory enough
using System;
using UnityEngine;
public class MonoBehaviourCachedRectTransform : MonoBehaviour
{
[HideInInspector, NonSerialized]
private RectTransform rectTransform;
public RectTransform RectTransform
{
get { return rectTransform != null ? rectTransform : (rectTransform = GetComponent<RectTransform>()); }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment