# Creating Custom Components and Scripts

## 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 [Inspector](../../the-unity-interface/the-tabs/inspector-tab), click the **Add Component** button.

![](https://3795241431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8XSUYVSlHMdPUNud-2%2F-M9Knhy1bLLeiid0H9XF%2F-M9KwxKQhORrf1wKq5QQ%2Fimage.png?alt=media\&token=24213e03-75b8-47c4-bb9e-a93d772b4c26)

Scroll down to **New script**.

![](https://3795241431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8XSUYVSlHMdPUNud-2%2F-M9Knhy1bLLeiid0H9XF%2F-M9Kzy9E7aJ4iAUlcZv_%2Fimage.png?alt=media\&token=2f915010-00ec-4c5b-8cc1-76d3c4bb7e92)

This will ask you for the name of your script and will let you know if it matches the name of an existing script."

{% hint style="danger" %}
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.
{% endhint %}

![](https://3795241431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8XSUYVSlHMdPUNud-2%2F-M9Knhy1bLLeiid0H9XF%2F-M9L-GTWBJxj7-nkPeyS%2Fimage.png?alt=media\&token=93c3eb26-8c3c-4f4d-bfb9-cee0f936272d)

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.&#x20;

![](https://3795241431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8XSUYVSlHMdPUNud-2%2F-M9Knhy1bLLeiid0H9XF%2F-M9L01qVwuoevRFB17Tp%2Fimage.png?alt=media\&token=bdb2f7e9-6a31-4486-b45d-16c303483ffa)

The script will now appear in the [Project ](../../the-unity-interface/the-tabs/project-tab)window, in the Assets folder, the list of components, and in the Inspector.

![](https://3795241431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8XSUYVSlHMdPUNud-2%2F-M9Knhy1bLLeiid0H9XF%2F-M9L0QiiyVdu3dPp1g8Z%2Fimage.png?alt=media\&token=6815f9a7-5a18-41aa-aa11-9f8f23ce80ab)

![](https://3795241431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8XSUYVSlHMdPUNud-2%2F-M9Knhy1bLLeiid0H9XF%2F-M9L0WtmV4I6-2IXbJ2t%2Fimage.png?alt=media\&token=17102911-ea09-4e15-ad65-0a7af657712a)

![](https://3795241431-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8XSUYVSlHMdPUNud-2%2F-M9Knhy1bLLeiid0H9XF%2F-M9L0_9Ja699C4zV15Qm%2Fimage.png?alt=media\&token=579a8aa7-ca70-46fb-9d1c-2bcec2221c8e)

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](../../coding-basics/intro-to-scripts) section for more information on the actual scripting.

### 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.&#x20;

{% hint style="danger" %}
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.
{% endhint %}

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.

{% hint style="danger" %}
Renaming scripts in the Project window will require additional renaming within the script. The script will not automatically update.
{% endhint %}

Please see the [Coding Basics](../../coding-basics/intro-to-scripts) section for more information on the actual scripting.

{% hint style="warning" %}
REMEMBER: Add the script to a game object in the scene. It will not work if it does not exist in the game.
{% endhint %}

{% content-ref url="../../select/components" %}
[components](../../select/components)
{% endcontent-ref %}

{% content-ref url="../../delete/components" %}
[components](../../delete/components)
{% endcontent-ref %}

