This script really makes my game lag!

var grassBlock : Transform;

function Update () {
for(var grassLayerX = -5; grassLayerX < 5; grassLayerX++)
for(var grassLayerZ = -5; grassLayerZ < 5; grassLayerZ++)
	grassBlock = Instantiate(grassBlock, Vector3 (grassLayerX, 0,grassLayerZ)Quaternion.identity);

The original script had the grass layer variables at -500.

This script is supossed to generate a flat grass terrain from a prefab I made. But with the original it won’t open. I tried compiling it and it would just come up with an errror screen I’ve never seen before saying : ERROR failed to initialize the player Could not preload global game manager #0. I think it’s saying something about the build settings and level 0 but I did set the level to 0 in the build settings. Then I tried making it -5 in the script above and it works but it’s SUPER laggy. The thing is it’s not my computer because I just got a brand new one and it’s has a really good processor and stuff all the newest parts and all other really HD games work smoothly.

So what’s wrong is it because of the generation? Will it get better FPS after a minute or 2? Please help!

The reason it is so laggy is that it is creating 100 or so objects every frame. From looking at your code, you want to change Update() to Start().

P.S. I guess that the reason that the -500 value didn’t work was because that would generate about 250,000 (500^2) objects.

EDIT: Also, it seems that you are trying to recreate Minecraft in Unity (based on your other questions). This is not a very good idea. Unity was not designed to do something like that, at least in the way you are going about it.