private void ClearTarget() { _target.Died -= _target_Invalid; _target.Finished -= _target_Invalid; _target = null; TowerAI.ClearTarget(); }
public Tower(BuilduingTypeInfo info, string type, Vector2 pos) : base(info, type, pos) { string[] coms = new string[info.Attacks.Length + info.SpawnAttacks.Length]; meleAtks = new ArealAttack[info.Attacks.Length]; int count = 0; foreach (AttackTypeInfo atk in info.Attacks) { coms[count] = "Mele " + count; meleAtks[count] = new ArealAttack(atk, this); count++; } spawnAtks = new SpawnAttack[info.SpawnAttacks.Length]; count = 0; foreach (SpawnAttackTypeInfo atk in info.SpawnAttacks) { coms[count + meleAtks.Length] = atk.SpawnActor + "-" + atk.Number; spawnAtks[count] = new SpawnAttack(atk, this); count++; } menu = new ActorMenu(this, coms); menu.CommandInvoked += new MenuItemPressed(menu_CommandInvoked); curSpawn = 0; curMele = 0; updateMenuInfo(); AI = new TowerAI(this); }
// Update is called once per frame void Update() { tower = BuildingManager.instance.GetCurrentPanelInfoTower(); towerScript = tower.GetComponent <TowerAI>(); updatePanel(); }
public void activateCircle() { GameObject spellCastSound = GameObject.FindGameObjectWithTag("Sound"); spellCastSound.GetComponent <AudioSource>().Play(); CircleCollider2D spellCollider = GetComponentInParent <CircleCollider2D>(); float spellRange = spellCollider.radius; spellRange = spellRange * GetComponentInParent <Transform>().localScale.x; GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); GameObject[] towers = GameObject.FindGameObjectsWithTag("Tower"); if (spell == 2 || spell == 3) { foreach (GameObject enemy in enemies) { Vector3 enemyPos = enemy.transform.position; enemyPos.z = 0; float distanceToEnemy = Vector3.Distance(transform.position, enemyPos); //print(spellRange); //print(distanceToEnemy); if (distanceToEnemy <= spellRange) { EnemyAI enemyScript = enemy.GetComponent <EnemyAI>(); if (spell == 2) //Heal { enemyScript.currentHealth = Mathf.Clamp(enemyScript.currentHealth + healPercent * enemyScript.enemy.Health, 0, enemyScript.enemy.Health); } else if (spell == 3) //Speed { enemyScript.speedBuff = true; } } } } else if (spell == 1) { foreach (GameObject tower in towers) { Vector3 towerPos = tower.transform.position; towerPos.z = 0; float distanceToTower = Vector3.Distance(transform.position, towerPos); if (distanceToTower <= spellRange) { TowerAI towerScript = tower.GetComponent <TowerAI>(); if (spell == 1)//Stun { towerScript.stun = true; } } } } Destroy(this.gameObject); }
// Update is called once per frame void Update() { if (Selector.selectedObject) { towerAI = Selector.selectedObject.GetComponent <TowerAI>(); destroyCost = Mathf.FloorToInt(0.75f * towerAI.tower.price * towerAI.hp / towerAI.tower.maxHp); destroyCostDisplay.SetText(destroyCost.ToString()); bool IsLastTower = false; if (GameOver.NumberOfTowers <= 1) { if (towerAI.gameObject.tag != "Wall") { IsLastTower = true; } } if (IsLastTower) { button.interactable = false; } else { button.interactable = true; } } }
private void SetTarget(UnitModel selectedUnit) { _target = selectedUnit; _target.Died += _target_Invalid; _target.Finished += _target_Invalid; TowerAI.SetTarget(_target); }
void Start() { tower = this.gameObject; towerAIScript = tower.GetComponent <TowerAI>(); buildingManager = BuildingManager.instance; upgraded = 0; towerType = tower.GetComponent <TowerAI>().towerType; upgradeCost = upgradeCostGrow; }
public void CreateTooltip() { TowerAI _TowerAI = Selector.selectedObject.GetComponent <TowerAI>(); Tooltip.CreateTowerTooltip_Static(upgradedTower, _TowerAI.attackDmgMultiplier, _TowerAI.attackRateMultiplier); Transform _range = Selector.selectedObject.transform.Find("Range"); _range.localScale = Vector2.one * upgradedTower.range * 2 * _TowerAI.rangeMultiplier; }
protected virtual void OnTriggerEnter2D(Collider2D other) { GameObject collidingObj = other.gameObject; if (friendly) { if (collidingObj.tag == "Enemy") { EnemyAI enemyAI = collidingObj.GetComponent <EnemyAI>(); if (!ignore.Contains(collidingObj)) { ignore.Add(collidingObj); int _damage = enemyAI.TakeDamage(attackDmg, armorPiercing); if (_damage > 0 || attackDmg == 0) { AudioManager.Play_Static(hitSound, true); } else if (_damage <= 0 && attackDmg != 0) { AudioManager.Play_Static("MetalHit", true); } foreach (Vector2 debuffID in debuffs) { switch (debuffID.x) { case 0: enemyAI.AddDebuff(new FireDebuff(debuffID.y, enemyAI)); break; case 1: enemyAI.AddDebuff(new SlowDebuff(debuffID.y, enemyAI)); break; default: break; } } OnHit(); } } } if (!friendly) { if (collidingObj.tag == "Tower" || collidingObj.tag == "Wall") { TowerAI towerAI = collidingObj.GetComponent <TowerAI>(); if (!ignore.Contains(collidingObj)) { ignore.Add(collidingObj); AudioManager.Play_Static(hitSound, true); towerAI.TakeDamage(attackDmg); OnHit(); } } } }
private void UpdateSupportBuffs() { foreach (GameObject tower in towersInRange) { if (tower) { TowerAI towerAI = tower.GetComponent <TowerAI>(); if (towerAI.attackDmgMultiplier - 1 == attackBoost) { towerAI.attackDmgMultiplier = 1; } if (towerAI.attackRateMultiplier - 1 == speedBoost) { towerAI.attackRateMultiplier = 1; } if (towerAI.rangeMultiplier - 1 == rangeBoost) { towerAI.rangeMultiplier = 1; } towerAI.target = null; } } towersInRange = FindTowersInRange(); foreach (GameObject tower in towersInRange) { if (tower) { TowerAI towerAI = tower.GetComponent <TowerAI>(); if (towerAI.attackDmgMultiplier - 1 < attackBoost) { towerAI.attackDmgMultiplier = attackBoost + 1; } if (towerAI.attackRateMultiplier - 1 < speedBoost) { towerAI.attackRateMultiplier = speedBoost + 1; } if (towerAI.rangeMultiplier - 1 < rangeBoost) { towerAI.rangeMultiplier = rangeBoost + 1; } towerAI.target = null; } } }
// Update is called once per frame void Update() { if (Selector.selectedObject) { towerAI = Selector.selectedObject.GetComponent <TowerAI>(); repairCost = Mathf.CeilToInt(towerAI.tower.price * (towerAI.tower.maxHp - towerAI.hp) / towerAI.tower.maxHp); if (0 < repairCost && repairCost <= MoneyManager.money) { button.interactable = true; } else { button.interactable = false; } repairCostDisplay.SetText(repairCost.ToString()); } }
public void Update(float deltaTime) { if (_target != null) { if (Position.DistanceTo(_target.Position) > TowerAI.Radius) { ClearTarget(); } } if (_target == null) { var left = Position.x - TowerAI.Radius; var right = Position.x + TowerAI.Radius; var top = Position.y + TowerAI.Radius; var bottom = Position.y - TowerAI.Radius; float distance = TowerAI.Radius; UnitModel selectedUnit = null; foreach (var unit in _map.Units) { if (unit.Position.x >= left && unit.Position.y <= right && unit.Position.y >= bottom && unit.Position.y <= top) { var dist = Position.DistanceTo(unit.Position); if (dist <= distance) { distance = dist; selectedUnit = unit; } } } if (selectedUnit != null) { SetTarget(selectedUnit); } } Direction = _target == null ? Vector2.up : (_target.Position - Position).normalized; if (_target != null) { TowerAI.Update(deltaTime); } }
void OnMouseDown() { if (EventSystem.current.IsPointerOverGameObject()) { return; } if (turret != null) { return; } if (BuildingManager.instance.getShopActivity()) { GameObject turretToBuild = BuildingManager.instance.GetTurretToBuild(); turretScrpt = turretToBuild.GetComponent <TowerAI>(); if (BuildingManager.instance.getMoney() >= turretScrpt.cost) { turret = (GameObject)Instantiate(turretToBuild, this.transform.position + offset, this.transform.rotation); turret.GetComponent <TowerAI>().setTowerNode(this.gameObject); BuildingManager.instance.purchase(turretScrpt.cost); } } }
protected override void OnDestroy() { foreach (GameObject tower in towersInRange) { if (tower) { TowerAI towerAI = tower.GetComponent <TowerAI>(); if (towerAI.attackDmgMultiplier - 1 == attackBoost) { towerAI.attackDmgMultiplier = 1; } if (towerAI.attackRateMultiplier - 1 == speedBoost) { towerAI.attackRateMultiplier = 1; } if (towerAI.rangeMultiplier - 1 == rangeBoost) { towerAI.rangeMultiplier = 1; } towerAI.target = null; } } }
// Start is called before the first frame update void Start() { towerAI = GetComponent <TowerAI>(); childCannon = transform.Find("CannonRotation").gameObject; }
void GetData(RaycastHit hitObj) { Data = hitObj.collider.GetComponent<TowerAI>(); Damage = Data.Damage; Armor = Data.Armor; Health = Data.Health; SellPrice = Data.SellPrice; Name = Data.Name; Level = Data.Level; var cam = Camera.mainCamera; Obj = hitObj.collider.gameObject; ScreenPos = cam.WorldToScreenPoint(Obj.transform.position); ScreenPos.y = Screen.height - ScreenPos.y; //Debug.Log("ScreenPos: " + ScreenPos); }
void Awake() { tower = transform.parent.GetComponent<TowerAI>(); }
/// <summary> /// Check if this enemy is revealed, if this enemy is invisible /// </summary> private void checkIfRevealed() { if (revealingTower == null) { GameObject[] towers = GameObject.FindGameObjectsWithTag("TOWER"); if (towers.Length > 0) { foreach (GameObject obj in towers) { revealDist = Vector2.Distance(transform.position, obj.transform.position); revealingTower = obj.GetComponent<TowerAI>(); if (revealingTower != null) { if (revealDist < revealingTower.attackRange && revealingTower.revealsInvisible) { isVisible = true; break; } } revealingTower = null; } } } else { revealDist = Vector2.Distance(transform.position, revealingTower.gameObject.transform.position); if (revealDist > revealingTower.attackRange) { revealingTower = null; isVisible = false; } } }
// Use this for initialization void Start() { aSource = GetComponent<AudioSource>(); revealingTower = null; revealDist = 0; }
private void Awake() { tower = GetComponent <TowerAI> (); animator = GetComponent <Animator> (); }
// Start is called before the first frame update void Start() { pulseImage = gameObject.GetComponent <SpriteRenderer>(); tower = transform.parent.gameObject.GetComponent <TowerAI>(); pulseFadeTimer = .5f; }
void Awake() { towerAI = gameObject.GetComponentInParent <TowerAI> (); }
//variables for specifying which enemy to target //private List<EnemyAI> currentEnemyList; //private EnemyAI currentEnemyScript; //private Transform currentEnemyTransform; // Start is called before the first frame update void Start() { tower = transform.parent.gameObject.GetComponent <TowerAI>(); //currentEnemyList = new List<EnemyAI>(); }
public void UpgradeTower() { TowerAI.UpgradeTower(); }
public void Initialize(MapModel map, Point position) { _map = map; Position = position; TowerAI.Initialize(Position); }
// Use this for initialization void Start() { revealingTower = null; revealDist = 0; aSource = GetComponent<AudioSource>(); renderer = this.GetComponent<SpriteRenderer>(); }