Exemple #1
0
 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
                 });
             }
         }
     }
 }
Exemple #2
0
    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
                    });
                }
            }
        }
    }
Exemple #3
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0) &&
         !EventSystem.current.IsPointerOverGameObject() &&
         activeBuildingType != null)
     {
         if (CanSpawnBuilding(activeBuildingType, UtilitiesClass.GetMouseWorldPosition(), out errorMessageCache) &&
             ResourceManager.Instance.CanAfford(activeBuildingType.constructionCostArray, out errorMessageCache))
         {
             ResourceManager.Instance.SpendResources(activeBuildingType.constructionCostArray);
             BuildingConstruction.Create(UtilitiesClass.GetMouseWorldPosition(), activeBuildingType);
             SoundManager.Instance.PlaySound(SoundManager.Sounds.BuildingPlaced);
         }
         else
         {
             TooltipUI.Instance.Show(errorMessageCache, true);
         }
     }
 }
Exemple #4
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
     {
         if (_activeBuildingType != null)
         {
             if (CanSpawnBuilding(_activeBuildingType, Utilities.GetMouseWorldPosition(), out string errorMessage))
             {
                 if (ResourceManager.Instance.CanAfford(_activeBuildingType.constructionResourceCostArray))
                 {
                     ResourceManager.Instance.SpendResources(_activeBuildingType.constructionResourceCostArray);
                     //Instantiate(_activeBuildingType.prefab, Utilities.GetMouseWorldPosition(), Quaternion.identity);
                     BuildingConstruction.Create(Utilities.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
                 });
             }
         }
         else
         {
             TooltipUI.Instance.Show("Choose building type first!", new TooltipUI.TooltipTimer {
                 timer = 2f
             });
         }
     }
 }