Пример #1
0
    public void TrySpawnAll()
    {
        foreach (Spawnable spawnable in spawnables)
        {
            startTime = Time.realtimeSinceStartup;
            for (int i = 0; i < spawnable.quantity; i++)
            {
                GameObject            prefab         = spawnable.prefabs.RandomElement();
                SpawnObstacle         prefabObstacle = prefab.GetComponentInChildren <SpawnObstacle>();
                SphericalRegionCircle prefabRegion   = (prefabObstacle != null)? prefabObstacle.region : null;
                Vector3 direction;
                bool    zeroDirection, outsideSpawnRegion, blockedBySomeObstacle;
                bool IsStillOnTime() => (curTime - startTime) <= maxTimeRandomizing;

                do
                {
                    direction             = UnityEngine.Random.insideUnitSphere.normalized;
                    curTime               = Time.realtimeSinceStartup;
                    zeroDirection         = direction == Vector3.zero;
                    outsideSpawnRegion    = !spawnRegion.Contains(direction);
                    blockedBySomeObstacle = SpawnObstacle.AnyBlocksSpawn(obstacleIds, prefabRegion, direction);
                } while ((zeroDirection || outsideSpawnRegion || blockedBySomeObstacle) && IsStillOnTime());
                if (!IsStillOnTime())
                {
                    Debug.Log("Timed out spawning " + prefab + " #" + (i + 1) + "." + (outsideSpawnRegion? " Outside spawn region.":"") + (blockedBySomeObstacle ? " Blocked by some obstacle." : ""));
                    break;
                }
                Transform newObj = Instantiate(prefab).transform;
                newObj.position = direction.normalized * radius;
                newObj.up       = direction;
                newObj.parent   = parent;
            }
            Debug.Log("Time spent spawning: " + (Time.realtimeSinceStartup - startTime));
        }
    }
    public void Initialization()
    {
        _spawnObstacle = Object.FindObjectOfType <SpawnObstacle>();
        _spawnZombie   = Object.FindObjectOfType <SpawnZombie>();

        _timeToSpawn = new TimeRemaining(SpawnTarget, Random.Range(_minDelay, _maxDelay), true);

        _timeToSpawn.AddTimeRemaining();
    }
Пример #3
0
    void Awake()
    {
        Player    = GameObject.Find("Player");
        rigPlayer = Player.GetComponent <Rigidbody2D>();

        startPositionPlayer = Player.transform.position;
        startRotationPlayer = Player.transform.rotation;

        scrSpawnObstacle = GetComponent <SpawnObstacle>();
        scrSave          = GetComponent <Save>();
        scrScores        = GetComponent <Scores>();
    }
Пример #4
0
    void increaseDifficulty()
    {
        SpawnObstacle    astroidSpawnerScript = astroidSpawner.GetComponent <SpawnObstacle>();
        SpawnObstacle    powerUpSpawnerScript = powerUpShipSpawner.GetComponent <SpawnObstacle>();
        PlayerMoveScript playerMove           = player.GetComponent <PlayerMoveScript>();

        if (adjustedScore >= 200 && adjustedScore < 500)
        {
            playerMove.speed = 11.0f;
        }
        else if (adjustedScore >= 500 && adjustedScore < 750)
        {
            astroidSpawnerScript.numToSpawnMax = 8;
            powerUpSpawnerScript.numToSpawnMax = 3;
            playerMove.speed = 11.5f;
        }
        else if (adjustedScore >= 750 && adjustedScore < 1000)
        {
            astroidSpawnerScript.numToSpawnMin = 4;
            powerUpSpawnerScript.numToSpawnMin = 2;
            playerMove.speed = 12.0f;
        }
        else if (adjustedScore >= 1000 && adjustedScore < 1500)
        {
            astroidSpawnerScript.numToSpawnMax = 10;
            powerUpSpawnerScript.numToSpawnMax = 5;
            playerMove.speed = 13.0f;
        }
        else if (adjustedScore >= 1500 && adjustedScore < 3000)
        {
            astroidSpawnerScript.numToSpawnMax = 15;
            astroidSpawnerScript.numToSpawnMin = 6;
            playerMove.speed = 13.5f;
        }
        else if (adjustedScore >= 3000)
        {
            astroidSpawnerScript.spawnTimeMin = 10;
            astroidSpawnerScript.spawnTimeMax = 15;
            playerMove.speed = 15.0f;
        }
    }