コード例 #1
0
    void SpawnAsteroid()
    {
        for (int i = 0; i < asteroids.Length; i++)
        {
            Vector2 position      = Vector2.zero;
            bool    validPosition = false;
            int     spawnAttempts = 0;

            while (!validPosition && spawnAttempts < maxSpawnAttempts)
            {
                spawnAttempts++;

                position = AsteroidSpace.RandomPosition(2.4f, 7, 30);

                validPosition = AsteroidSpace.CheckOverlap(position, obstacleRadius);
            }
            Instantiate(asteroids[i], position, Quaternion.identity);
        }
    }
コード例 #2
0
    void SpawnDisabler()
    {
        Vector2 position = AsteroidSpace.RandomPosition(2.2f, 5, 25);

        Instantiate(shootDisabler, position, Quaternion.identity);
    }
コード例 #3
0
    void LateUpdate()
    {
        if (isChangeable && !getsBigger)
        {
            if (health < 30 && hugeAsteroid.activeSelf)
            {
                ActivateAsteroid(largeAsteroid, hugeAsteroid);
            }

            if (health < 21 && largeAsteroid.activeSelf)
            {
                ActivateAsteroid(mediumAsteroid, largeAsteroid);
            }
            if (health < 11 && mediumAsteroid.activeSelf)
            {
                ActivateAsteroid(smallAsteroid, mediumAsteroid);
            }
        }
        if (getsBigger)
        {
            if (health < 11 && smallAsteroid.activeSelf)
            {
                ActivateAsteroid(mediumAsteroid, smallAsteroid);
            }
        }
        if (health <= 0)
        {
            if (isChangeable)
            {
                smallAsteroid.SetActive(false);
            }

            GameManager.instance.score += scoreForDestruction;
            hasExploded = true;
        }

        transform.Rotate(0, 0, rotationDeg * Time.deltaTime);
        transform.Translate(Vector2.down * fallSpeed * Time.deltaTime, Space.World);
        if (transform.position.y < fallY || hasExploded)
        {
            smallAsteroid.SetActive(false);
            mediumAsteroid.SetActive(false);
            largeAsteroid.SetActive(false);
            hugeAsteroid.SetActive(false);

            hasExploded = false;

            Vector2 position      = Vector2.zero;
            bool    validPosition = false;
            int     spawnAttempts = 0;

            while (!validPosition && spawnAttempts < maxSpawnAttempts)
            {
                spawnAttempts++;
                position      = AsteroidSpace.RandomPosition(spawnX, minSpawnY, maxSpawnY);
                validPosition = AsteroidSpace.CheckOverlap(position, obstacleRadius);
            }
            transform.position = position;
            activeAsteroid.SetActive(true);
            health    = healthReset;
            fallSpeed = Random.Range(fallSpeedX, fallSpeedY);
        }
        if (Player.isDead)
        {
            gameObject.SetActive(false);
        }
    }