/// <summary> /// Start this instance. /// </summary> void Start() { DefendersSpawner defendersSpawner = tower.GetComponent <DefendersSpawner>(); if (defendersSpawner != null) { // Get all active defenders foreach (GameObject defender in defendersSpawner.defPoint.GetDefenderList()) { DamageTaker damageTaker = defender.GetComponent <DamageTaker>(); // Heal it damageTaker.TakeDamage(-damageTaker.hitpoints); if (healFxPrefab != null) { // Create heal visual effect Destroy(Instantiate(healFxPrefab, defender.transform), fxDuration); } } } else { Debug.Log("This tower can not use heal skills"); } Destroy(gameObject); }
/// <summary> /// Sells the tower with half of price. /// </summary> /// <param name="emptyPlacePrefab">Empty place prefab.</param> public void SellTower(GameObject emptyPlacePrefab) { DefendersSpawner defendersSpawner = GetComponent <DefendersSpawner>(); // Destroy defenders on tower sell if (defendersSpawner != null) { foreach (KeyValuePair <GameObject, Transform> pair in defendersSpawner.defendersList) { Destroy(pair.Key); } } CloseActions(); Price price = GetComponent <Price>(); uiManager.AddGold(price.price); // Place building place GameObject newTower = Instantiate <GameObject>(emptyPlacePrefab, transform.parent); newTower.transform.position = transform.position; newTower.transform.rotation = transform.rotation; // Destroy old tower Destroy(gameObject); }
/// <summary> /// Sells the tower with half of price. /// </summary> /// <param name="emptyPlacePrefab">Empty place prefab.</param> public void SellTower(GameObject emptyPlacePrefab) { CloseActions(); DefendersSpawner defendersSpawner = GetComponent <DefendersSpawner>(); // Destroy defenders on tower sell if (defendersSpawner != null) { foreach (KeyValuePair <GameObject, Transform> pair in defendersSpawner.defPoint.activeDefenders) { Destroy(pair.Key); } } Price price = GetComponent <Price>(); uiManager.AddGold(price.price / 2); // Place building place GameObject newTower = Instantiate <GameObject>(emptyPlacePrefab, transform.parent); newTower.name = emptyPlacePrefab.name; newTower.transform.position = transform.position; newTower.transform.rotation = transform.rotation; // Destroy old tower Destroy(gameObject); EventManager.TriggerEvent("TowerSell", null, null); }
public void Clear() { gameObject = null; price = null; tower = null; spawner = null; towerActions = null; navAgent = null; damageTaker = null; aiFeature = null; attack = null; range = null; flying = false; attackType = 0; targetCommon = false; targetFlying = false; }
/// <summary> /// Shows the unit info. /// </summary> /// <param name="info">Info.</param> public void ShowUnitInfo(UnitInfo info, GameObject obj) { if (info.unitName != "") { unitName.text = info.unitName; } else { unitName.text = obj.name; } if (info.primaryIcon != null || info.secondaryIcon != null || info.primaryText != "" || info.secondaryText != "") { primaryText.text = info.primaryText; secondaryText.text = info.secondaryText; if (info.primaryIcon != null) { primaryIcon.sprite = info.primaryIcon; primaryIcon.gameObject.SetActive(true); } if (info.secondaryIcon != null) { secondaryIcon.sprite = info.secondaryIcon; secondaryIcon.gameObject.SetActive(true); } } else { DamageTaker damageTaker = obj.GetComponentInChildren <DamageTaker>(); Attack attack = obj.GetComponentInChildren <Attack>(); DefendersSpawner spawner = obj.GetComponentInChildren <DefendersSpawner>(); // Automaticaly set primary icon and text if (damageTaker != null) { primaryText.text = damageTaker.hitpoints.ToString(); primaryIcon.sprite = hitpointsIcon; primaryIcon.gameObject.SetActive(true); } else { if (attack != null) { if (attack != null) { primaryText.text = attack.cooldown.ToString(); primaryIcon.sprite = cooldownIcon; primaryIcon.gameObject.SetActive(true); } } else if (spawner != null) { primaryText.text = spawner.cooldown.ToString(); primaryIcon.sprite = cooldownIcon; primaryIcon.gameObject.SetActive(true); } } if (attack != null) { secondaryText.text = attack.damage.ToString(); if (attack is AttackMelee) { secondaryIcon.sprite = meleeAttackIcon; } else if (attack is AttackRanged) { secondaryIcon.sprite = rangedAttackIcon; } secondaryIcon.gameObject.SetActive(true); } else { if (spawner != null) { secondaryText.text = spawner.maxNum.ToString(); secondaryIcon.sprite = defendersNumberIcon; secondaryIcon.gameObject.SetActive(true); } } } gameObject.SetActive(true); }