Example #1
0
 /// <summary>
 /// deals damage to the building
 /// </summary>
 /// <param name="damage">number of the damage dealt</param>
 public void HurtBuilding(int damage)
 {
     life -= damage;
     if (life < 0)
     {
         life = 0;
         cooldownBeforeRespawn = 0;
         Destroy(this.gameObject.GetComponent <BoxCollider2D>());
         (gameObject.GetComponent <SpriteRenderer>()).sprite = spriteDestroy;
         SoundManager.instance.RandomizeSfx(this.BuildingDestroyedSound);
         PlayerUnitBuilding building = gameObject.GetComponent <PlayerUnitBuilding>();
         if (building != null)
         {
             building.isDestroyed = true;
         }
     }
 }
Example #2
0
 ///checking for the Respawn if needed in the update
 void Update()
 {
     if (cooldownBeforeRespawn < RespawnCooldown)
     {
         cooldownBeforeRespawn++;
         if (cooldownBeforeRespawn == RespawnCooldown)
         {
             life = maxlife;
             this.gameObject.AddComponent <BoxCollider2D>();
             this.gameObject.GetComponent <BoxCollider2D>().isTrigger = true;
             (gameObject.GetComponent <SpriteRenderer>()).sprite      = spriteAlive;
             PlayerUnitBuilding building = gameObject.GetComponent <PlayerUnitBuilding>();
             if (building != null)
             {
                 building.isDestroyed = false;
             }
         }
     }
 }