Beispiel #1
0
 private void Update()
 {
     if (CanClick && Input.GetMouseButtonDown(0) && ParentProduction.IsProductionOverlayActive &&
         !ParentProduction.BuildingClickedProduction.Tile.HasUnit())
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit touchBox;
         if (Physics.Raycast(ray, out touchBox))
         {
             if (touchBox.collider == this.collider)
             {
                 BuildingGameObject buildingToProduceFrom = ParentProduction.BuildingClickedProduction;
                 // Kind of ugly yet could not find better solution. The unit is created before we check if it can be bought.
                 // Set it inactive immediatly and then check for enough Gold. If not then destroy else decrease the Gold and set it active.
                 UnitGameObject unit = CreatorFactoryUnit.CreateUnit(buildingToProduceFrom.Tile,
                                                                     buildingToProduceFrom.index, type);
                 unit.gameObject.SetActive(false);
                 if (lm.CurrentLevel.CurrentPlayer.CanBuy(unit.UnitGame.Cost))
                 {
                     unit.gameObject.SetActive(true);
                     lm.CurrentLevel.CurrentPlayer.DecreaseGoldBy(unit.UnitGame.Cost);
                     CanClick = false;
                     ParentProduction.InitiateMoving(true);
                 }
                 else
                 {
                     Notificator.Notify("Not enough gold!", 1.5f);
                     unit.DestroyUnit();
                 }
             }
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// When a unit captured an trainingzone, train him to his hero form.
 /// </summary>
 /// <param Name="unitToHero">The unit to train to an hero.</param>
 private void OnTrainingzoneCapturedHero(UnitGameObject unitToHero)
 {
     if (!unitToHero.isHero)
     {
         Tile        tiletoSpawn = unitToHero.Tile;
         PlayerIndex index       = unitToHero.index;
         UnitTypes   type        = unitToHero.type;
         unitToHero.DestroyUnit();
         CreatorFactoryUnit.CreateHeroUnit(tiletoSpawn, index, type);
     }
 }