Need a "Instantiating Prefabs at runtime" explanation

First of all. I got it to work. I spent a good hour and half on it, but my first trip-up in this example was getting it run. No matter how many times I’ve played it, I wouldn’t see any cubes falling down. Here’s the script I’m using:

using UnityEngine;
using System.Collections;
public class Instantiation : MonoBehaviour {
    // Use this for initialization
    public Transform brick;
  
    void Start() {
        for (int y = 0; y < 5; y++) {
            for (int x = 0; x < 5; x++) {
                Instantiate(brick, new Vector3(x, y, 0), Quaternion.identity);
            }
        }
    }
  
    // Update is called once per frame
    void Update () {
  
    }
}

And here’s the instructions I’m following on creating the “Brick” prefab and adding a reference to the script’s brick variable.

Now we only need to create the Prefab,
which we do in the Editor. Here’s how:

  1. Choose GameObject->Create
    Other->Cube
  2. Choose Component->Physics->Rigidbody
  3. Choose Assets->Create->Prefab
  4. In the Project View, change the name
    of your new Prefab to “Brick”
  5. Drag the cube you created in the
    Hierarchy onto the “Brick” Prefab in
    the Project View
  6. With the Prefab created, you can
    safely delete the Cube from the
    Hierarchy (Delete on Windows,
    Command-Backspace on Mac)

We’ve created our Brick Prefab, so now
we have to attach it to the brick
variable in our script. When you
select the empty GameObject that
contains the script, the Brick
variable will be visible in the
inspector.

Now drag the “Brick” Prefab from the
Project View onto the brick variable
in the Inspector. Press Play and
you’ll see the wall built using the
Prefab.

Now let me show you what happens when I press play.

Again, it took me an hour and a half until a light bulb switched on in my head. I dragged and dropped the script file, from the project viewer, onto the the hierarchy viewer.

Then the magic begins.

Obviously I’m new to Unity 3D since I’m following the manual and all, but I would appreciate an explanation on what I did to get it to work.

Unity’s components – including renderers, cameras, and even your scripts – only execute if they’re attached to a GameObject in your scene.

In your first video, you drag a script out of the project view and drop it on the hierarchy view. This does nothing, because you dropped the script onto nothing. It wasn’t attached, so it didn’t execute.

In your second video, you drag a script out of the project view, and drop it onto the “Main Camera” GameObject. This does work, because your script is now attached in the scene, and so it executes.

You can confirm this by examining the Main Camera object in the inspector; you should find that your script is now attached to it.