Beispiel #1
0
    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);
    }
Beispiel #2
0
    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);
    }
Beispiel #3
0
    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);
                }
            }
        }
    }