modular-unity-scripts
A collection of simple ‘drag-n-drop’ style unity C# scripts that satisfy common game development requirements.
Preface
The idea is to speed up unity developer workflow by providing ready-made scripts that can be quickly dropped on an object and then set up exclusively through easy to understand public variables. The target audience of these scripts includes unity developers of all skill levels - tooltips should explain public variable functionality as if the user is a complete beginner. If nothing else these scripts may serve as a good starting point or reference for more complex / coarse grained scripts.
Note: I am new on the block, so any feedback or criticisms you have are most welcome 😃
Catalogue
View the CATALOGUE.md file for a list of all script names, categories and descriptions.
Usage
- Clone this repository and place the
ModularScripts
folder inside your Unity Project’sAssets
directory - Drag-n-drop a script onto a Unity gameobject
- Configure the script’s public variables to your liking (hover over any particular property for a description of what effect it will have)
DIY Template
If you want to quickly generate a template that follows the script conventions outlined at the bottom of this readme, follow these steps:
- Clone this repository and place the
Editor
folder inside the root of your Unity Project’sAssets
directory - Choose
Edit->Generate Self-Describing C# Script
- Choose a directory for your new script
- Rename both the
NewScript
filename as well as thepublic class NewScript
(note: they must be the same) - Update relevant details seen in template document (script description etc.)
Categories
name | description |
---|---|
effect |
visual effects - aesthetic stuff that looks pretty |
management |
object/file management - toggling / renaming of objects etc. |
messaging |
event/script triggering based on a condition - send messaging when entered a collider etc. |
motion |
gameobject/character movement whether it be transform or physics based |
spawning |
instantiation and destruction of objects |
tools |
handy miscellaneous scripts |
ui |
2D legacy GUI and unity canvas scripts |
Conventions
All scripts must have a:
-
PascalCase name - e.g.
ScriptName
-
Self-describing comment at the beginning of the class detailing the author, year and function of the script
/* Script created by Lachlan McKay 2016 © * This script allows you to clamp the transform of an object */
-
Neatly formatted public variables with logical groupings and helpful tooltips
[Header("Main Options")] [Tooltip("Foo string says foo.")] public string foo;
-
Credits and description block as shown:
//Credits and description [Header("_© Lachlan McKay 2016_")] [TextArea(2,2)] public string ScriptDescription = "Script description."; private string ScriptTags = "script name search tags space delimited"; private string ScriptCategory = "category";
-
Public
ScriptDescription
string that describes the function of the script -
Private
ScriptTags
string that contains search terms related to the script -
Private
ScriptCategory
string that loosely categorizes the script - see above for available categories -
ToggleScript()
function with single bool input that enables/disables script functionality (where applicable)//Enables or disables the script's update function public void ToggleScript(bool state) { active = state; this.enabled = state; if (debugConsole) { print("Setting active state of " + this.GetType().Name + " script to: " + state + " at time: " + Time.time); } }