コード例 #1
0
ファイル: Spawner_VFP.cs プロジェクト: tartuke/LivingDungeon
    IEnumerator Spawn()
    {
        yield return(new WaitForSeconds(spawnTime));

        GameObject temp;
        float      xOffset = transform.position.x;
        float      yOffset = transform.position.y;

        if (isSpawningFromPlayer)
        {
            xOffset = playerTransform.position.x;
            yOffset = playerTransform.position.y;
        }

        for (int i = 0; i < spawnCount; i++)
        {
            if (numSpawned <= maxSpawned)
            {
                yield return(new WaitForEndOfFrame());

                float x, y;
                int   count = 0;
                do
                {
                    int xNeg = (Random.Range(0, 100) > 50) ? 1 : -1;
                    int yNeg = (Random.Range(0, 100) > 50) ? 1 : -1;

                    float randX = Random.Range(0, maxSpawnRadius - minSpawnRadius);
                    float randY = Random.Range(0, maxSpawnRadius - minSpawnRadius);

                    x = xOffset + (minSpawnRadius + randX) * xNeg;
                    y = yOffset + (minSpawnRadius + randY) * yNeg;

                    if (count++ > 5)
                    {
                        break;
                    }
                } while (!mapManager.IsFloor(x, y));

                temp = Instantiate(spawnObject, new Vector3(x, y, 0), new Quaternion(), enemyEmpty);

                mapManager.tileGrowth.Equations.Add(new PointDisplacement(temp.transform, 1, 1, false));

                numSpawned++;
            }
        }


        if (spawnTime != 0 && !isPaused && isRepeating)
        {
            StartCoroutine("Spawn");
        }
    }
コード例 #2
0
    IEnumerator Spawn()
    {
        yield return(new WaitForSeconds(Random.Range(0, spawnTime)));

        GameObject temp;
        float      xOffset = transform.position.x;
        float      yOffset = transform.position.y;

        if (isSpawningFromPlayer)
        {
            xOffset = playerTransform.position.x;
            yOffset = playerTransform.position.y;
        }

        for (int i = 0; i < spawnCount; i++)
        {
            if (numSpawned <= maxSpawned)
            {
                yield return(new WaitForEndOfFrame());

                float x, y;
                int   count = 0;
                do
                {
                    if (Random.Range(0, 100) > 50)
                    {
                        x = xOffset + (minSpawnRadius + Random.Range(0, maxSpawnRadius - minSpawnRadius));
                    }
                    else
                    {
                        x = xOffset - (minSpawnRadius + Random.Range(0, maxSpawnRadius - minSpawnRadius));
                    }

                    if (Random.Range(0, 100) > 50)
                    {
                        y = yOffset + (minSpawnRadius + Random.Range(0, maxSpawnRadius - minSpawnRadius));
                    }
                    else
                    {
                        y = yOffset - (minSpawnRadius + Random.Range(0, maxSpawnRadius - minSpawnRadius));
                    }
                } while (!mapManager.IsFloor(x, y));

                temp = Instantiate(spawnObject, new Vector3(x, y, 0), new Quaternion(), enemyEmpty);

                mapManager.tileGrowth.Equations.Add(new PointDisplacement(temp.transform, 1, 1, false));
                numSpawned++;
                if (count++ > 5)
                {
                    break;
                }
            }
        }

        boidManager.Setup();

        // if spawntime is 0 you'll crash the game
        if (isRepeating && spawnTime != 0 && !isPaused)
        {
            StartCoroutine("Spawn");
        }
    }