private void OnDestroy() { if (Instance == this) { Instance = null; } }
// Kvieciamas tik tada kai paspaudziama ant movables layer neturincio pastato public void DeselectBuildings() { if (selectedBuildingIndex != -1) { if (EmptySpot(selectedBuildingIndex)) { ClearSquares(selectedBuildingIndex, buildingsLocations[selectedBuildingIndex]); buildingsLocations[selectedBuildingIndex] = new BuildingLocation(buildings[selectedBuildingIndex].transform.position.x, buildings[selectedBuildingIndex].transform.position.y, buildings[selectedBuildingIndex].transform.position.z); FillSquares(selectedBuildingIndex, buildingsLocations[selectedBuildingIndex]); } else { buildings[selectedBuildingIndex].transform.position = new Vector3(buildingsLocations[selectedBuildingIndex].x, buildingsLocations[selectedBuildingIndex].y, buildingsLocations[selectedBuildingIndex].z); buildingBasisMeshRenderers[selectedBuildingIndex].material = green; } if (buildings[selectedBuildingIndex].transform.position == new Vector3(0, -100, 0)) { CanonManager canonManager = buildings[selectedBuildingIndex].GetComponent(typeof(CanonManager)) as CanonManager; CrossbowManager crossbowManager = buildings[selectedBuildingIndex].GetComponent(typeof(CrossbowManager)) as CrossbowManager; if (canonManager != null) { AddAndRemove.instance.SellCanon(); } else if (crossbowManager != null) { AddAndRemove.instance.SellCrossbowTower(); } } PutBuildingBack(selectedBuildingIndex); selectedBuildingIndex = -1; selectedBuildingArrows.transform.position = new Vector3(0, -100, 0); } removeBuildingButton.gameObject.SetActive(false); }
private void Awake() { if (Instance == null) { Instance = this; } }
//----------------------------------------------------------------------------------------------------- //Kvieciamas kai paspaudziama ant movables layer turincio pastato public void SelectBuilding(int index) { if (index != selectedBuildingIndex) { if (selectedBuildingIndex != -1) { if (EmptySpot(selectedBuildingIndex)) { ClearSquares(selectedBuildingIndex, buildingsLocations[selectedBuildingIndex]); buildingsLocations[selectedBuildingIndex] = new BuildingLocation(buildings[selectedBuildingIndex].transform.position.x, buildings[selectedBuildingIndex].transform.position.y, buildings[selectedBuildingIndex].transform.position.z); FillSquares(selectedBuildingIndex, buildingsLocations[selectedBuildingIndex]); } else { buildings[selectedBuildingIndex].transform.position = new Vector3(buildingsLocations[selectedBuildingIndex].x, buildingsLocations[selectedBuildingIndex].y, buildingsLocations[selectedBuildingIndex].z); buildingBasisMeshRenderers[selectedBuildingIndex].material = green; } if (selectedBuildingIndex != index) { PutBuildingBack(selectedBuildingIndex); BringBuildingNearer(index); } } else { BringBuildingNearer(index); } if (selectedBuildingIndex != -1 && buildings[selectedBuildingIndex].transform.position == new Vector3(0, -100, 0)) { CanonManager canonManager = buildings[selectedBuildingIndex].GetComponent(typeof(CanonManager)) as CanonManager; CrossbowManager crossbowManager = buildings[selectedBuildingIndex].GetComponent(typeof(CrossbowManager)) as CrossbowManager; if (canonManager != null) { AddAndRemove.instance.SellCanon(); } else if (crossbowManager != null) { AddAndRemove.instance.SellCrossbowTower(); } } BuildingPlacement.instance.SetItem(buildings[index], buildingsDimensions[index]); SetArrowsLocalPosition(index); selectedBuildingArrows.transform.position = new Vector3(buildings[index].transform.position.x, 0, buildings[index].transform.position.z); BringArrowsNearer(); selectedBuildingIndex = index; } removeBuildingButton.gameObject.SetActive(true); }
private void PutBuildingBack(int buildingIndex) { CanonManager canonManager = buildings[buildingIndex].GetComponent(typeof(CanonManager)) as CanonManager; CrossbowManager crossbowManager = buildings[buildingIndex].GetComponent(typeof(CrossbowManager)) as CrossbowManager; if (canonManager != null) { canonManager.PutBack(); } else if (crossbowManager != null) { crossbowManager.PutBack(); } }