void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { if (_activeBuildingType != null) { if (CanSpawnBuilding(_activeBuildingType, UtilsClass.GetMouseWorldPosition(), out string errorMessage)) { if (ResourceManager.Instance.CanAfford(_activeBuildingType.constructionResourceCostArray)) { ResourceManager.Instance.SpendResources(_activeBuildingType.constructionResourceCostArray); BuildingConstruction.Create(UtilsClass.GetMouseWorldPosition(), _activeBuildingType); SoundManager.Instance.PlaySound(SoundManager.Sound.BuildingPlaced); } else { TooltipUI.Instance.Show("Cannot afford " + _activeBuildingType.GetConstructionResourceCostString(), new TooltipUI.TooltipTimer { Timer = 2f }); } } else { TooltipUI.Instance.Show(errorMessage, new TooltipUI.TooltipTimer { Timer = 2f }); } } } }
private void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { // Condition to be able to select a construciton to build if (activeBuildingType != null) { if (CanSpawnBuilding(activeBuildingType, UtilsClass.GetMouseWorldPosition(), out string errorMessage)) { // Do you can afford the building? if (ResourceManager.Instance.CanAfford(activeBuildingType.constructResourceCostArray)) { // Time to pay... ResourceManager.Instance.SpendResouces(activeBuildingType.constructResourceCostArray); // Congratulations!! Time to Instantiate you new BUILDING!! //Instantiate(activeBuildingType.prefab, UtilsClass.GetMouseWorldPosition(), Quaternion.identity); BuildingConstruction.Create(UtilsClass.GetMouseWorldPosition(), activeBuildingType); } else { // Trying to be smart? TooltipUI.Insntace.Show("Cannot afford " + activeBuildingType.GetConstructionResourceCostString(), new TooltipUI.TooltipTimer { timer = 2f }); } } else { TooltipUI.Insntace.Show(errorMessage, new TooltipUI.TooltipTimer { timer = 2f }); } } } }
private void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { if (activeBuildingType != null) { if (CanSpawnBuilding(activeBuildingType, UtilsClass.GetMouseWorldPosition(), out string errorMessage)) { if (ResourceManager.Instance.CanAfford(activeBuildingType.constructionResourceCostArray)) { ResourceManager.Instance.SpendResources(activeBuildingType.constructionResourceCostArray); Instantiate(activeBuildingType.prefab, UtilsClass.GetMouseWorldPosition(), Quaternion.identity); } else { TooltipUI.Instance.Show("Cannot afford " + activeBuildingType.GetConstructionResourceCostString(), new TooltipUI.TooltipTimer { timer = 2f }); } } else { TooltipUI.Instance.Show(errorMessage, new TooltipUI.TooltipTimer { timer = 2f }); } } } }
private void Update() { //mouseVisualTransform.position = GetMouseWorldPosition(); canBuild = CanSpawnBuilding(activeBuildingType, UtilsClass.GetMouseWorldPosition(), out string errorMessage); if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { if (activeBuildingType != null) { if (canBuild) { if (ResourceManager.Instance.CanAfford(activeBuildingType.constructionResourceCostArray)) { ResourceManager.Instance.SpendResources(activeBuildingType.constructionResourceCostArray); //Instantiate(activeBuildingType.prefab, UtilsClass.GetMouseWorldPosition(), Quaternion.identity); BuildingConstruction.Create(UtilsClass.GetMouseWorldPosition(), activeBuildingType); SoundManager.Instance.PlaySound(SoundManager.Sound.BuildingPlaced); } else { TooltipUI.Instance.Show("Cannot afford " + activeBuildingType.GetConstructionResourceCostString(), new TooltipUI.TooltipTimer { timer = 2f }); } } else { TooltipUI.Instance.Show(errorMessage, new TooltipUI.TooltipTimer { timer = 2f }); } } } }