Skip to content

Instantly share code, notes, and snippets.

@AnzyGit
Last active December 20, 2023 02:59
Show Gist options
  • Save AnzyGit/00608b69111be8471e748b266adc4900 to your computer and use it in GitHub Desktop.
Save AnzyGit/00608b69111be8471e748b266adc4900 to your computer and use it in GitHub Desktop.
Access modifiers cheat sheet in UNITY
using UnityEngine;
public class CommonAccessModifiers : MonoBehaviour
{
// VISIBLE/EDITABLE from the inspector, this script
// and other scripts
public int MyCounter1;
// VISIBLE/EDITABLE in this script, and VISIBLE
// in other scripts
public int MyCounter2 { get; private set; }
// VISIBLE/EDITABLE from the inspector and this script
[SerializeField]
private int _myCounter3;
// VISIBLE only in this script
private int _myCounter4;
// VISIBLE only in this script, and subclasses
protected int MyCounter5;
}
public class AdvancedAccessModifiers : MonoBehaviour
{
// VISIBLE/EDITABLE from the inspector, this script and
// VISIBLE in other scripts
[field:SerializeField]
public int MyCounter6 { get; private set; }
// VISIBLE/EDITABLE from this script and other scripts
[HideInInspector]
public int MyCounter7 = 12;
// VISIBLE/EDITABLE from the inspector (for instances)
[System.Serializable]
public class MyInnerClass
{
public int myInt = 10;
public Color myColor = Color.white;
}
public MyInnerClass MyInnerClassInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment