Exemplo n.º 1
0
    bool FindAndSortEnemies()
    {
        foreach (var e in WaveSpawner.GetEnemyList_Static())
        {
            targetList.Add(e.GetComponent <Enemy>());
        }

        if (targetList.Count <= 0)
        {
            return(false);
        }

        targetList.Sort((a, b) => {
            return(b.distanceTravelled.CompareTo(a.distanceTravelled));
        });
        return(true);
    }
Exemplo n.º 2
0
    List <GameObject> FilterEnemiesInRange(bool global)
    {
        List <GameObject> enemiesInRange = new List <GameObject>();

        //only see enemies in range
        if (global == false)
        {
            foreach (var e in WaveSpawner.GetEnemyList_Static())
            {
                float d = Vector3.Distance(pivot.position, e.transform.position);
                if (d <= range)
                {
                    enemiesInRange.Add(e);
                }
            }
        }
        else   //see all enemies
        {
            enemiesInRange = WaveSpawner.GetEnemyList_Static();
        }
        return(enemiesInRange);
    }
Exemplo n.º 3
0
    void Explode()
    {
        //save the enemy list copy
        List <GameObject> e = new List <GameObject>(WaveSpawner.GetEnemyList_Static());

        //remove enemies not in explosion range
        for (int i = 0; i < e.Count - 1; i++)
        {
            if (Vector3.Distance(transform.position, e[i].transform.position) > explosionRadius)
            {
                e.RemoveAt(i);
            }
        }
        e.TrimExcess();

        //sort enemies based on distance to target/explosion
        e.Sort((a, b) => {
            return(Vector3.Distance(transform.position, a.transform.position).CompareTo(Vector3.Distance(transform.position, b.transform.position)));
        });


        //if penetration is smaller then it will use max pentration, but if there arent as many viable enemies, then the penetration will match the enemy count
        penetration = Mathf.Min(penetration, e.Count);

        var s = WaveSpawner.GetEnemyList_Static();

        for (int i = 0; i < penetration; i++)
        {
            if (Vector3.Distance(transform.position, e[i].transform.position) <= explosionRadius)
            {
                Damage(e[i].transform);
            }
        }
        target = null;
        ObjectPool.instance.Deactivate(gameObject);
    }