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:
- Choose GameObject->Create
Other->Cube- Choose Component->Physics->Rigidbody
- Choose Assets->Create->Prefab
- In the Project View, change the name
of your new Prefab to “Brick”- Drag the cube you created in the
Hierarchy onto the “Brick” Prefab in
the Project View- 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.
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.