GameObject[] GetDamagables() { List <GameObject> list = new List <GameObject>(); RaycastHit[] hits = Physics.SphereCastAll(this.transform.position, attackRange.Value, Vector3.up); foreach (RaycastHit hit in hits) { I_IDamagable damagable = hit.collider.gameObject.GetComponent <I_IDamagable>(); if (damagable != null) { list.Add(hit.collider.gameObject); } } return(list.ToArray()); }
void Attack(GameObject go) { timeToAttack -= Time.deltaTime; if (timeToAttack <= 0) { I_IDamagable dmgable = go.GetComponent <I_IDamagable>(); so_DataSet.Attribute healthSo = dmgable.GetSoDataSet().Attributes.Where(x => x.Name == scr_Attributes.Attribute.Health).First(); if (healthSo.TakeFromLocalDataSet) { scr_DataSet.Attribute healthScr = dmgable.GetScrDataSet().Attributes.Where(x => x.Name == scr_Attributes.Attribute.Health).First(); healthScr.Value -= damage.Value; } else { healthSo.Value -= damage.Value; } timeToAttack = fireRate.Value; } }
void Update() { if (health.Value <= 0) { Destroy(this.gameObject); return; } if (_StatsGlobal.Energy < 0) { return; } if (timeLeftToFire > 0) { timeLeftToFire -= Time.deltaTime; } GameObject enemy = GetEnemy(); if (enemy != null) { RotateHeadTowards(enemy.transform.position); RotateCannoneTowards(enemy.transform.position); if (timeLeftToFire <= 0 && IsLookingAtEnemy(enemy)) { I_IDamagable damagable = enemy.GetComponent <I_IDamagable>(); if (damagable == null) { throw new Exception("GameObject with tag " + scr_Tags.Enemy + " need I_IDamagable script!"); } so_DataSet.Attribute soHealth = damagable.GetSoDataSet().Attributes.Where(x => x.Name == scr_Attributes.Attribute.Health).FirstOrDefault(); if (soHealth == null) { throw new Exception("I_IDamagable needs health attribute!"); } if (soHealth.TakeFromLocalDataSet) { scr_DataSet.Attribute scrHealth = damagable.GetScrDataSet().Attributes.Where(x => x.Name == scr_Attributes.Attribute.Health).FirstOrDefault(); if (scrHealth == null) { throw new Exception("I_IDamagable needs health attribute!"); } scrHealth.Value -= damage.Value; } else { soHealth.Value -= damage.Value; } GameObject go = Instantiate(_LaserPrefab); go.transform.position = _FirePosition.transform.position; go.transform.LookAt(enemy.transform.position); float distance = Vector3.Distance(_FirePosition.transform.position, enemy.transform.position); go.GetComponent <I_ILaser>().SetLength(distance); shotSource.Play(); timeLeftToFire = fireRate.Value; } } else { RotateToDefault(); } }
void ShootWeapon() { RaycastHit hit; Ray ray = new Ray(bullet_Spawn.position - (bullet_Spawn.right / 2), bullet_Spawn.right); Debug.DrawRay(ray.origin, ray.direction, Color.blue); if (Physics.Raycast(ray, out hit, range.Value)) { Transform objectHit = hit.transform; bool damageDeal = false; if (objectHit) { scr_DecoOnDamage decoScript = objectHit.GetComponent <scr_DecoOnDamage>(); if (decoScript) { decoScript.MarkDamaged(); } I_IDamagable targetDamagable = objectHit.GetComponent <I_IDamagable>(); if (targetDamagable != null) { so_DataSet.Attribute sotargetHealth = targetDamagable.GetSoDataSet().Attributes.Find(x => x.Name == scr_Attributes.Attribute.Health); if (sotargetHealth.TakeFromLocalDataSet) { scr_DataSet.Attribute targetHealth = targetDamagable.GetScrDataSet().Attributes.Find(x => x.Name == scr_Attributes.Attribute.Health); if (targetHealth != null) { targetHealth.Value -= dmg.Value; damageDeal = true; } } if (damageDeal) { so_DataSet.Attribute typeOfOreBonus = targetDamagable.GetSoDataSet().Attributes.Find(x => x.Name == scr_Attributes.Attribute.Gale); if (typeOfOreBonus != null) { _StatsGlobal.CrystalGale += (int)typeOfOreBonus.Value; } if (typeOfOreBonus == null) { typeOfOreBonus = targetDamagable.GetSoDataSet().Attributes.Find(x => x.Name == scr_Attributes.Attribute.Dida); if (typeOfOreBonus != null) { _StatsGlobal.CrystalDida += (int)typeOfOreBonus.Value; } } if (typeOfOreBonus == null) { typeOfOreBonus = targetDamagable.GetSoDataSet().Attributes.Find(x => x.Name == scr_Attributes.Attribute.Iron); if (typeOfOreBonus != null) { _StatsGlobal.Iron += (int)typeOfOreBonus.Value; } } if (typeOfOreBonus == null) { typeOfOreBonus = targetDamagable.GetSoDataSet().Attributes.Find(x => x.Name == scr_Attributes.Attribute.Stone); if (typeOfOreBonus != null) { _StatsGlobal.Stone += (int)typeOfOreBonus.Value; } } if (typeOfOreBonus == null) { typeOfOreBonus = targetDamagable.GetSoDataSet().Attributes.Find(x => x.Name == scr_Attributes.Attribute.Coal); if (typeOfOreBonus != null) { _StatsGlobal.Coal += (int)typeOfOreBonus.Value; } } } //else //nothing! //{ // sotargetHealth.Value -= dmg; //} } } } }