Creating a script and using it as a component
In addition to Unity's built-in components, we can also create script components. When you create a script and attach it to a GameObject, you can see the component you created in the GameObject's Inspector window, just like Unity's built-in components.
How to create a new script in Unity
It is very easy to create a new C# script in Unity. I will introduce two different ways to do it.
Firstly, you can right-click the Project panel in the Unity Editor, and then a menu will pop up. You only need to select Create | C# Script, then the Unity Editor will create a C# file in the folder identified in the Project panel.
The filename of the new script is NewBehaviourScript.cs
by default. You can change the name when creating it.
For example...