void RegisterWithFloor() { // TO FIX OUT OF BOUNDS if (rc.mc.GetFloorAt(this.transform.position) != null) { currentFloor = rc.mc.GetFloorAt(this.transform.position); currentFloor.AddTown(this); } }
// main loop depending on game states private void Update() { switch (gameState) { case GameState.SpawnRoad: if (Input.GetKeyDown(KeyCode.Space)) { rc.rg.DoRoads(); } break; case GameState.SpawnUnit: if (Input.GetMouseButtonDown(0)) { // On left-click round to the nearest Floor location (integer value) Vector3 spawnPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); spawnPos.x = Mathf.Round(spawnPos.x); spawnPos.y = Mathf.Round(spawnPos.y); spawnPos.z = 0; // find the floor object at the desired spawn location Floor floor = rc.mc.GetFloorAt(spawnPos); // test to see if floor exists if (floor != null) { // if exists, check if there's a unit already there and if not, spawn here if (floor.hasUnit == false) { floor.AddUnit(Instantiate(unitPrefab, spawnPos, Quaternion.identity)); } } } // un-select SpawnUnit mode on right click if (Input.GetMouseButtonDown(1)) { gameState = GameState.Default; } break; case GameState.SpawnTown: if (Input.GetMouseButtonDown(0)) { // On left-click round to the nearest Floor location (integer value) Vector3 spawnPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); spawnPos.x = Mathf.Round(spawnPos.x); spawnPos.y = Mathf.Round(spawnPos.y); spawnPos.z = 0; // find the floor object at the desired spawn location Floor floor = rc.mc.GetFloorAt(spawnPos); // test to see if floor exists if (floor != null) { // if exists, check if there's a unit already there and if not, spawn here if (floor.hasTown == false) { floor.AddTown(Instantiate(townPrefab, spawnPos, Quaternion.identity)); } } } // un-select SpawnTown mode on right click if (Input.GetMouseButtonDown(1)) { gameState = GameState.Default; } break; case GameState.NextTurn: // Gather relevant resources Unit[] units = FindObjectsOfType <Unit>(); foreach (Unit u in units) { u.GatherResources(); } turn++; gameState = GameState.Default; break; case GameState.Default: if (Input.GetKeyDown(KeyCode.Space)) { gameState = GameState.NextTurn; } break; } }