A loop to create to setup hundreds of prefabs...

My script requires me to setup hundreds of prefabs. I know how to set up one:

public GameObject MyPrefab1;

Great! But I need to setup +600. I can write the line of code +600 times with a different number at the end, but I’m sure I can do it with a loop.

Set up a variable (say x), create a loop that increases it by 1 until it reach the number I want (say 600). Each time it loops it sets up a variable as follows: MyPrefab+x

Here is the thing: I’m totally confused about the actual sytax… I now what to do, just not how. :-/

Any help will be greatly appreciated.

I suspect you’re confusing prefabs and instances: the prefab is the original object, from which you can instantiate how many clones you want (and name them “Clone1”, “Clone2” etc.). If you actually want to create 600 clones of myPrefab, you can use something like this:

public GameObject myPrefab; // drag here the prefab from the Project view

void CreateClones(int howMany){
  for (int i = 0; i < howMany; i++){
    // calculate the position for each new prefab:
    Vector3 pos = new Vector3(...);
    // create the clone:
    GameObject clone = Instantiate(myPrefab, pos, Quaternion.identity) as GameObject;
    // name it:
    clone.name = "Clone"+i.ToString();
  }
}