private bool isPossiblePath(int positionX, int positionY, int direction, mapData data) { if (data.getTileOnLayer(positionX, positionY, "path") == 1 || data.getTileOnLayer(positionX, positionY, "path") == 2) { return(false); } /**/ if (direction == 0 || direction == 1) { if (data.getTileOnLayer(positionX - 1, positionY, "path") == 2 || data.getTileOnLayer(positionX + 1, positionY, "path") == 2) { return(false); } if (direction == 0 && data.getTileOnLayer(positionX, positionY + 1, "path") == 2) { return(false); } if (direction == 1 && data.getTileOnLayer(positionX, positionY - 1, "path") == 2) { return(false); } } if (direction == 2 || direction == 3) { if (data.getTileOnLayer(positionX, positionY - 1, "path") == 2 || data.getTileOnLayer(positionX, positionY + 1, "path") == 2) { return(false); } if (direction == 2 && data.getTileOnLayer(positionX + 1, positionY, "path") == 2) { return(false); } if (direction == 3 && data.getTileOnLayer(positionX - 1, positionY, "path") == 2) { return(false); } } return(true); }
void Update() { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (mousePosition.x < -0.5f || mousePosition.y < -0.5f) { mousePosition.x = -2; mousePosition.y = -2; } int mousePositionX = (int)(mousePosition.x + 0.5f); int mousePositionY = (int)(mousePosition.y + 0.5f); mapData mapData = gamemanager.instance.mapData; mapGfx mapGfx = gamemanager.instance.mapGfx; if (mapData == null || mapGfx == null) { return; } int tileOnMousePosition = mapData.getTileOnLayer(mousePositionX, mousePositionY, "tower"); if (_buildTower == true && tileOnMousePosition != -1 && tileOnMousePosition != 1) { _mouseOverObject.SetActive(true); _mouseOverObject.transform.position = new Vector2(mousePositionX, mousePositionY); if (Input.GetMouseButtonDown(0) && _towers.ContainsKey(_towerTag)) { mapData.setTileOnLayer(mousePositionX, mousePositionY, "tower", 1); GameObject newTower = Instantiate(_towers[_towerTag], new Vector2(mousePositionX, mousePositionY), Quaternion.identity) as GameObject; mapGfx.addGameObject(newTower, "tower"); switch (_towerTag) { case "waterTower": elementaryAffection.instance.waterLevel++; break; case "fireTower": elementaryAffection.instance.fireLevel++; break; case "airTower": elementaryAffection.instance.airLevel++; break; case "earthTower": elementaryAffection.instance.earthLevel++; break; } elementaryAffection.instance.updateOnChange(); } } else { _mouseOverObject.SetActive(false); } if (Input.GetMouseButtonDown(1)) { _buildTower = false; } }