private void AddCubeAtLocation(PrefabCube cubeToInstantiate, float x, float y, float z) { if (x >= map.width || y >= map.height || z >= map.depth) return; GameObject go = Instantiate(cubeToInstantiate.Prefab, new Vector3(x * cubeToInstantiate.Prefab.transform.localScale.x, y * cubeToInstantiate.Prefab.transform.localScale.y, z * cubeToInstantiate.Prefab.transform.localScale.z), Quaternion.identity) as GameObject; map.AddBlock(cubeToInstantiate.CubeCode, (int)x, (int)y, (int)z); }
void Update() { if (Input.GetMouseButtonDown(0)) { if (Input.GetKey(KeyCode.S)) HandleAddCube(); else HandleMoveToBlock(); } if (Input.GetKeyDown(KeyCode.Q)) SelectedCube = Cubes[0]; if (Input.GetKeyDown(KeyCode.W)) SelectedCube = Cubes[1]; if (Input.GetKeyDown(KeyCode.E)) SelectedCube = Cubes[2]; }
private void InstantiateFromMap() { /* Clear the currently loaded game objects * instantiate the objects from our map */ for(int x = 0; x < map.width; ++x) { for(int y = 0; y < map.height; ++y) { for(int z = 0; z < map.depth; ++z) { if (map.GetCubeCode(x, y, z) == -1) { /* Spawn air block */ /* ... which is a skip for now */ } else { /* Treat it normal */ SelectedCube = GetPrefabCubeFromCode(map.GetCubeCode (x, y, z)); AddCubeAtLocation(SelectedCube, x, y, z); } } } } }
// Use this for initialization void Start() { SelectedCube = Cubes[0]; CreateInitialFloor(); }
public Box(Color color) { mesh = new PrefabCube(color); }