void SetBlock(Vector3 p, Block b) { RaycastHit hit; int i = 0; Chunck chunck = Chunck.GetChunck(Mathf.FloorToInt(p.x), Mathf.FloorToInt(p.y), Mathf.FloorToInt(p.z)); Vector3 localPos = chunck.transform.position - p; if (b == null) { map = chunck.GetBlock(p); if (map == null) { map = Block.getBlock(BlockList.Blocks[tmp].BlockName); } item = GetItem(map); if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 7f, lm)) { if (hit.transform.gameObject.tag != "Obje") { if (hit.transform.gameObject.tag != "Tree") { if (hit.transform.gameObject.tag != "Player") { GameObject obje = Instantiate(Resources.Load <GameObject>(map.BlockName), BlockHighlight.transform.position + new Vector3(0, 0.5f, 0), Quaternion.identity) as GameObject; obje.GetComponent <Obje>().item = item; Debug.Log("Obje = " + obje.transform.position + "Chunck Pos = " + chunck.transform.position + "P=" + p + "Local Pos=" + localPos); } } } } } map = null; if ((Mathf.FloorToInt(localPos.x) * -1) == (Chunck.Width)) { Chunck c = Chunck.GetChunck(Mathf.FloorToInt(p.x + 5), Mathf.FloorToInt(p.y), Mathf.FloorToInt(p.z)); if (c == null) { return; } c.SetBlock(p + new Vector3(+1, 0, 0), b); } else { Chunck c = Chunck.GetChunck(Mathf.FloorToInt(p.x - 5), Mathf.FloorToInt(p.y), Mathf.FloorToInt(p.z)); if (c == null) { return; } c.SetBlock(p + new Vector3(+1, 0, 0), b); } chunck.SetBlock(p + new Vector3(+1, 0, 0), b); }
void Update() { tmp = Random.Range(2, 10); if (Mathf.FloorToInt(Time.time) % 5 == 0 && once) { for (float x = transform.position.x - viewRange; x < transform.position.x + viewRange; x += Chunck.Width * gridSize) { for (float z = transform.position.z - viewRange; z < transform.position.z + viewRange; z += Chunck.Width * gridSize) { int xx = Mathf.FloorToInt(x / Chunck.Width) * Chunck.Width; int zz = Mathf.FloorToInt(z / Chunck.Width) * Chunck.Width; Chunck chunck = Chunck.GetChunck(Mathf.FloorToInt(xx), 0, Mathf.FloorToInt(zz)); if (chunck == null) { for (int y = 0; y < collumnHeight; y++) { int yr = (y * Chunck.Height) /*- (y)*/; for (int ix = 0; ix < gridSize; ix++) { for (int iz = 0; iz < gridSize; iz++) { GameObject ch = Instantiate(chunckPrefab, new Vector3(xx + (Chunck.Width * ix), yr, zz + (Chunck.Width * iz)), Quaternion.identity); } } } } } } once = false; } else { once = true; } BlockController(); SundriesController(); Chunck c = Chunck.GetChunck(10, 90, 10); if (c == null) { return; } }