Why so slow ???

Hi guys,

I created a little minecraft clone but it is really slow!

My PC isnt slow at all so here is the PC data : intel core i 5 450m , nvidia geforce 540m , 8gb ram ddr3

and here is the code for the chunk ( i think this is the problem)

using UnityEngine;
using System.Collections;

public class ChunkGenerator : MonoBehaviour {
	
	public Transform Block1;
	public Transform Block2;
	public Transform Block3;
	public Transform Block4;
	
	public static float noiseScale = 0.03568182f;
	public static Vector3 offset = new Vector3(0,0,0);
	
	
	void Start () {
	
		
		
				float mountMaxHeight =24;
				
				int w = 8;
		
		for(int x = 0;x < 16;x++){
			
			for(int y = 0;y < 16;y++){
				
				for(int z = 0;z < 16;z++){
		
				float value;	
					
				
				float offX = x + offset.x+transform.position.x;
				float offY = y + offset.y;
				float offZ = z + offset.z+transform.position.z;
				
				float mountHeight = (Mathf.PerlinNoise(offX*noiseScale, offZ*noiseScale)-0.5f)*mountMaxHeight;
					
					
					
				if(y > mountHeight) value = -1; else value = 1;	
					
					
				if(y==w-8) value = mountHeight+8;
                if(y==w-7) value = mountHeight+7;
                if(y==w-6) value = mountHeight+6;
                if(y==w-5) value = mountHeight+5;
                if(y==w-4) value = mountHeight+4;
                if(y==w-3) value = mountHeight+3;
                if(y==w-2) value = mountHeight+2;
                if(y==w-1) value = mountHeight+1;
                if(y==w) value = mountHeight;
                if(y==w+1) value = mountHeight-1;
                if(y==w+2) value = mountHeight-2;
                if(y==w+3) value = mountHeight-3;
                if(y==w+4) value = mountHeight-4;
                if(y==w+5) value = mountHeight-5;
                if(y==w+6) value = mountHeight-6;
                if(y==w+7) value = mountHeight-7;
                if(y==w+8) value = mountHeight-8;
					
					
					
					
					
					
					
					
					
					if(value > 1){
					
		
						if(y < 3+Random.Range(-1,1)){	
					
					
						Instantiate(Block2,transform.position + new Vector3(x,y,z),Quaternion.identity);
					
					
						}
						else{
						
							
						Instantiate(Block1,transform.position + new Vector3(x,y,z),Quaternion.identity);	
							
						}	
						
					}
					
				}
			}
		}
	}
	
	
	
}

and for the terrain

using UnityEngine;
using System.Collections;

public class CreateTerrain : MonoBehaviour {

public Transform chunk;
public Transform player;

ArrayList posxz = new ArrayList();


int size = 16;     // number of cubes along a side = resolution (cannot put too high, 65k vertex limit per mesh)


private Vector3 lastpos = new Vector3(0,0,0);


void Awake () 
{
		
		
		
		

lastpos = player.transform.position;

InitChunk();

}
	
void InitChunk() {

float ax = (Mathf.Ceil(player.transform.position.x/16)-1);
float az = (Mathf.Ceil(player.transform.position.z/16)-1);

int y = 0;




	for(int x = -1;x <= 1;x++){
		for(int z = -1;z <= 1;z++){
			
			
			float cx = (ax+x);
			float cz = (az+z);
			
			Vector2 cxz = new Vector2(cx,cz);
			
			if(!posxz.Contains(cxz)) {
			
			
			Instantiate(chunk, transform.position + new Vector3(cxz.x,y,cxz.y)*size, transform.rotation);
			
			
			
			
			
			
			
			
			
			
			posxz.Add(cxz);
			
			
			
			
			
			
	






			
		}
	}





}

}


void Update() {




	if(player.transform.position != lastpos) {


	InitChunk();


	lastpos = player.transform.position;


	}

}
}

please help thanks!

You can’t generate individual GameObjects for every single block and expect to get good performance. See one of the many Minecraft threads that exist about using the Mesh class to create chunks. Also don’t use obsolete collection types like ArrayList.

–Eric