IEnumerator SpawnWave()
    {
        while (true)
        {
            float timeBetweenSpawn = waves[currentWave].spawnRate;

            if (activeWave)
            {
                GameObject newEnemy;
                if (waves[currentWave].bombEveryNormal != 0)
                {
                    if (bombDecider == 0)
                    {
                        newEnemy    = pool.SpawnFromPool("Bomb", firstPoint, Quaternion.identity);
                        bombDecider = waves[currentWave].bombEveryNormal;
                    }
                    else
                    {
                        newEnemy = pool.SpawnFromPool("Normal", firstPoint, Quaternion.identity);
                        bombDecider--;
                    }
                }
                else
                {
                    newEnemy = pool.SpawnFromPool("Normal", firstPoint, Quaternion.identity);
                }



                activeEnemies.Add(newEnemy);
                EnemiesLeft--;
            }

            if (EnemiesLeft == 0)
            {
                activeWave = false;
                if (currentWave < waves.Length - 1)
                {
                    print("reset");

                    currentWave++;
                }

                SetUpWave();
            }

            yield return(new WaitForSeconds(timeBetweenSpawn));
        }
    }
    IEnumerator Shoot()
    {
        while (true)
        {
            if (shooting)
            {
                GameObject objToShoot;
                int        lowestIndex = int.MaxValue;

                for (int i = 0; i < possibleEnemies.Count; i++)
                {
                    int currentIndex = waveManager.activeEnemies.IndexOf(possibleEnemies[i]);
                    if (currentIndex < lowestIndex)
                    {
                        lowestIndex = currentIndex;
                    }
                }

                objToShoot = waveManager.activeEnemies[lowestIndex];
                GameObject bul = pool.SpawnFromPool("Bullet", transform.position, Quaternion.identity);

                bul.GetComponent <Bullet_Script>().SetTarget(objToShoot);
            }
            yield return(new WaitForSeconds(1f / (float)shotsPerSecond));
        }
    }
    IEnumerator Shoot()
    {
        while (true)
        {
            List <GameObject> thingsToShoot = new List <GameObject>();

            if (shootTile1 != null)
            {
                foreach (GameObject enemy in shootTile1.GetComponent <CurrentEnemies>().currentEnemiesCheck)
                {
                    thingsToShoot.Add(enemy);
                }
            }

            if (shootTile2 != null)
            {
                foreach (GameObject enemy in shootTile2.GetComponent <CurrentEnemies>().currentEnemiesCheck)
                {
                    thingsToShoot.Add(enemy);
                }
            }

            foreach (GameObject obj in thingsToShoot)
            {
                obj.GetComponent <Health_Script>().RemoveHealth(1);
            }

            if (shootTile1 != null)
            {
                GameObject bul1 = pool.SpawnFromPool("Bullet", transform.position, Quaternion.identity);
                bul1.GetComponent <Bullet_Script>().SetTarget(shootTile1);
            }
            if (shootTile2 != null)
            {
                GameObject bul2 = pool.SpawnFromPool("Bullet", transform.position, Quaternion.identity);
                bul2.GetComponent <Bullet_Script>().SetTarget(shootTile2);
            }



            yield return(new WaitForSeconds(1f / shotsPerSeconds));
        }
    }
예제 #4
0
    public bool CreateGrid()
    {
        Reset_Object();

        // Total grid size (for a cube)
        grid_size = resolution * resolution * resolution;

        // Create 3D grid
        grid_ = new GameObject[resolution, resolution, resolution];

        // Bottom left of object
        start_pos = transform.position - new Vector3(transform.localScale.x / 2.0f, transform.localScale.y / 2.0f, transform.localScale.z / 2.0f);

        // Calculate the scale of each object
        object_scale = new Vector3(this.transform.localScale.x / resolution, this.transform.localScale.y / resolution, this.transform.localScale.z / resolution);

        // Create grid of Gameobjects
        GameObject temp_object;

        for (int i = 0; i < resolution; i++)
        {
            for (int j = 0; j < resolution; j++)
            {
                for (int k = 0; k < resolution; k++)
                {
                    // Spawn a gameobject at start position using the objects from the object pool
                    temp_object =                     //Instantiate(test_cube, start_pos, Quaternion.identity, grid_parent.transform) as GameObject;
                                  object_pooler.SpawnFromPool("Cube", start_pos, Quaternion.identity, region_parent.transform);

                    // Set new position and scale
                    temp_object.transform.localScale = object_scale;                    // new Vector3(this.transform.localScale.x/resolution,test_cube.transform.localScale.y,this.transform.localScale.z/resolution);
                    temp_object.transform.position   = start_pos
                                                       + new Vector3(object_scale.x / 2.0f, object_scale.y / 2.0f, object_scale.z / 2.0f)
                                                       + new Vector3((this.transform.localScale.x / resolution) * i, (this.transform.localScale.y / resolution) * j, (this.transform.localScale.z / resolution) * k);

                    // Assign cube
                    grid_[i, j, k] = temp_object;
                }
            }
        }

        // Create array of regions
        regions = new region[region_amount];

        // Create random region positions
        for (int r = 0; r < region_amount; r++)
        {
            // Create new region at random point
            GameObject region_sphere = Instantiate(region_clone, transform.position, Quaternion.identity, region_parent.transform) as GameObject;
            region_sphere.transform.position = grid_[Random.Range(0, resolution), Random.Range(0, resolution), Random.Range(0, resolution)].transform.position;

            // Assign control point
            regions[r].control_point = region_sphere;

            // Assign random colour
            temp_color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
            region_sphere.GetComponent <Renderer>().material.color = temp_color;
            regions[r].color = temp_color;

            // Assign parent
            regions[r].parent = region_sphere;

            regions[r].members = new List <GameObject>();
        }

        // Hide actual object
        this.GetComponent <MeshRenderer>().enabled = false;

        create_grid = false;
        created_    = true;
        return(true);
    }