This is a short overview of how scripting inside Unity works.
Scripting inside Unity consists of attaching custom script objects called behaviours to game objects. Different functions inside the script objects are called on certain events. The most used ones being the following:
This function is called before rendering a frame. This is where most game behaviour code goes, except physics code.
This function is called once every physics time step. This is the place to do physics-based game behaviour.
Code outside any function:
Code outside functions is run when the object is loaded. This can be used to initialise the state of the script.
You can also define event handlers. These all have names starting with On, (i.e. OnCollisionEnter). To see the full list of predefined events, see the documentation for MonoBehaviour.