Some more extensive script templates for C# development.
- Place the script templates (the .cs.txt files) into the script template folder:
PC: "C:\Program Files\Unity\Editor\Data\Resources\ScriptTemplates" (or similar)
MAC: /Applications/Unity/Unity.app/Contents/Resources/ScriptTemplates/ (or similar)
Note: do not change the ".cs.txt" extension.
- Restart Unity if it was open when you added the files to the script template folder.
- Right-click in the Project window and choose "Create >".
- Pick a script template of your choice.
The standard MonoBehaviour subclass with a few added magical Unity event functions:
- Awake(): Called when #SCRIPTNAME# is loaded, even if the behaviour is disabled but not if the GameObject it is attached to is inactive.
- Start(): Called right before the first Update() after #SCRIPTNAME# is enabled.
- OnEnable(): Called when #SCRIPTNAME# is enabled, before Start().
- OnDisable(): Called when #SCRIPTNAME# is disabled, either specifically or right before the GameObject is destroyed.
- OnDrawGizmosSelected(): Draw gizmos when GameObject that #SCRIPTNAME# is attached to is selected.
- OnDrawGizmos(): Draw gizmos of the GameObject that #SCRIPTNAME# is attached to.
- OnValidate(): Called when the script is loaded or a value is changed in the inspector (Called in the editor only).
A subclass of ScriptableObject. Useful for scripts that do not need to attach to specific GameObjects. Contains the following magical Unity event functions:
- OnEnable(): Called when #SCRIPTNAME# is enabled.
- OnDisable(): Called when #SCRIPTNAME# is disabled.
- OnDestroy(): Called when #SCRIPTNAME# is destroyed.
An empty class in global namespace. Useful for objects that do not directly interact with the Unity libraries.
A completely empty .cs file. Useful for quickly creating a very custom code file.
A subclass of the UnityEditor.Editor class that is used for making custom inspectors for classes.