Creating Custom Components and Scripts
Last updated
Last updated
Sometimes, you have to make your own component. These are called Scripts and use C# and Unity's libraries and classes. These built-in libraries and classes allow you to use very little script compared to coding everything by scratch.
To add a custom component through the Inspector, click the Add Component button.
Scroll down to New script.
This will ask you for the name of your script and will let you know if it matches the name of an existing script."
Script names should: 1. Have no spaces 2. Use only letters and numbers 3. Not start with a number 4. Use "Pascal casing" (capitalize each word) 5. Be descriptive
Not following these "rules" could break scripts.
Type in the name of your script and you are absolutely sure that's what you want to name it, click the Create and Add button.
The script will now appear in the Project window, in the Assets folder, the list of components, and in the Inspector.
The script can now be edited in the IDE/code editor set up with Unity (usually Visual Studio or MonoDevelop).
Please see the Coding Basics section for more information on the actual scripting.
Add a C# Script using the Assets > Create menu or right-clicking in the Project window.
This will create a script asset within the current folder with the name highlighted ready to change.
Script names should: 1. Have no spaces 2. Use only letters and numbers 3. Not start with a number 4. Use "Pascal casing" (capitalize each word) 5. Be descriptive
Not following these "rules" could break the script.
Press the ENTER key to confirm the name.
The script can now be edited in the IDE/code editor set up with Unity (usually Visual Studio or MonoDevelop).
After editing, the script will need to be added to the game object or asset for it to run.
Renaming scripts in the Project window will require additional renaming within the script. The script will not automatically update.
Please see the Coding Basics section for more information on the actual scripting.
REMEMBER: Add the script to a game object in the scene. It will not work if it does not exist in the game.