public virtual List <GameObject> EnemyNonAirUnits() { var results = new List <GameObject>(); foreach (GameObject enemy in EnemyObjects()) { GameUnit gu = enemy.GameUnit(); if (!gu.IsOfType(typeof(AirVehicle)) && !gu.IsOfType(typeof(Projectile))) { results.Add(enemy); } } return(results); }
public virtual List <GameObject> EnemyBuildingUnits() { var results = new List <GameObject>(); foreach (GameObject enemy in EnemyObjects()) { GameUnit gu = enemy.GameUnit(); if (gu.IsOfType(typeof(GroundBuilding))) { results.Add(enemy); } } return(results); }
public void ApplyForcesAndDamageStep() { Vector3 explosionPos = transform.position; Collider[] colliders = Physics.OverlapSphere(explosionPos, currentBlastRadius); // find objects in current blast radius foreach (Collider hit in colliders) { GameObject go = hit.gameObject; GameUnit unit = go.GameUnit(); if (unit && unit != this) { // apply force to rigid body if it has one Rigidbody rb = hit.GetComponent <Rigidbody>(); if (rb) { rb.AddExplosionForce(pushPower, explosionPos, currentBlastRadius, 0.2f); } // apply damage to unit //float dist = Vector3.Distance(explosionPos, unit.gameObject.transform.position); //float maxDamage = 1f; //float damage = maxDamage / (1f + dist); float a = 3f; if (unit.IsOfType(typeof(Vehicle))) { unit.ApplyDamage(a * 8f * (1 - DoneRatio())); } else { unit.ApplyDamage(a * 0.2f); } } } }