Unity Basics
  • Welcome
  • Getting Started with Unity Software
  • Helpful Shortcuts
  • The Unity Software Interface
    • The Default Interface
    • The Windows (Tabs)
      • Hierarchy Window
      • Scene Window
      • Project Window
      • Inspector Window
      • Game Window
      • Console Window
    • Other Layouts
      • Create a Custom Layout
  • Create
    • Creating Game Objects
      • 3D Primitives
      • Creating Game Objects in the Editor
      • Spawning Objects
      • Unhiding/Hiding Objects During Gameplay
      • Parenting
    • Creating Assets
    • Creating Components and Scripts
      • Adding Components in the Inspector
      • Creating Custom Components and Scripts
    • Creating Prefabs
  • Select and Update
    • General Selection
    • Search and Focus
    • Updating Game Objects
      • Updating Game Objects in the Editor
      • Updating Prefabs
    • Updating Assets
    • Updating Components
      • Update Components in the Inspector
      • Accessing Components Through Scripts
  • Delete
    • Deleting Game Objects
      • Deleting and Disabling Objects in the Editor
      • Using the Destroy() Function
    • Deleting Components and Scripts
      • Disabling and Removing Components in the Editor
      • Disabling and Removing Components During Gameplay
  • Translate, Rotate, and Scale
    • Intro to Transforms
    • Handy Transform Shortcuts
    • Translate
      • Positioning Game Objects in the Editor
      • Updating Position Through Script Code
      • Using the Transform.Translate() Function
    • Rotate
      • Rotating Game Objects in the Editor
      • Updating Rotation Through Script Code
      • Using the Transform.Rotate() Function
    • Scale
      • Resizing/Scaling Objects in the Editor
      • Updating Scale Through Script Code
    • Controlling Speed
    • Common Issues with Transforms
  • Materials
    • Material Basics
      • Creating and Applying Materials
      • Accessing Materials Through Code
  • Physics
    • Physics Basics
    • Colliders and Triggers
      • Collider Component Overview
      • Accessing Colliders Through Scripts
      • Common Issues: Colliders and Triggers
    • Rigidbody Component
      • Rigidbody Component Overview
      • Accessing the Rigidbody Component Through Scripts
      • Common Issues: Rigidbody Components
    • Common Issues: Physics and Velocity
  • Interaction
    • Interaction Basics
    • Keyboard Controls
    • Mouse Controls
  • Coding Basics
    • Intro to Scripts
    • Variables
    • Conditionals (If / Then / Else)
    • Arrays
    • Loops
    • Functions
Powered by GitBook
On this page
  • Creating a Custom Component / Script Through the Inspector
  • Creating a Script Through the Project Tab

Was this helpful?

  1. Create
  2. Creating Components and Scripts

Creating Custom Components and Scripts

PreviousAdding Components in the InspectorNextCreating Prefabs

Last updated 4 years ago

Was this helpful?

Creating a Custom Component / Script Through the Inspector

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 , 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 can now be edited in the IDE/code editor set up with Unity (usually Visual Studio or MonoDevelop).

Creating a Script Through the Project Tab

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.

REMEMBER: Add the script to a game object in the scene. It will not work if it does not exist in the game.

The script will now appear in the window, in the Assets folder, the list of components, and in the Inspector.

Please see the section for more information on the actual scripting.

Please see the section for more information on the actual scripting.

Project
Coding Basics
Coding Basics
Updating Components
Deleting Components and Scripts
Inspector