Create a C# script
Right-click the blank space of the Project, and click C# Script in Create to create a script.
After the creation is successful, a new script will be generated in Assets, rename it and create a new folder named Scripts, and drag all the created scripts into this folder to prevent more scripts from being used in the future The project window is too messy.
Double-click to open the c# script, the figure below is the default opening format of a new c# script.
Start: Called when the game object begins to exist (when the scene is loaded or the game object is instantiated).
Update: will be called every frame.
FixedUpdate: Called every physics time step.
OnBecameVisible and OnBecamelnvisible: Called when the game object's renderer enters or leaves the camera's view.
OnCollisionEnter and OnTriggerEnter: Called when a physical collision or trigger occurs.
OnDestroy: Called when the game object is destroyed.
The MonoBehaviour class is a base class from which all Unity scripts are derived by default. When you create a C# script from Unity's project window, it automatically inherits from MonoBehaviour and provides you with a template script.
The MonoBehaviour class provides the framework, allowing you to attach scripts to game objects in the editor, and provides hooks for common events such as Start and Update.