Пример #1
0
    void CreateSmallerAsteroid(float radiusDivider)
    {
        GameObject     smallerAsteroid = Instantiate(this.asteroidPrefab, transform.position, Quaternion.identity);
        AsteroidScript asteroidScript  = smallerAsteroid.GetComponent <AsteroidScript>();

        asteroidScript.Initialize(this.radius / radiusDivider);
    }
Пример #2
0
    void SpawnAsteroid()
    {
        float     asteroidX    = 0.0f;
        float     asteroidY    = 0.0f;
        const int maximumTries = 10;

        for (int i = 0; i < maximumTries; i++)
        {
            asteroidX = Random.Range(-this.asteroidSpawnBoundBox.x, this.asteroidSpawnBoundBox.x);
            asteroidY = Random.Range(-this.asteroidSpawnBoundBox.y, this.asteroidSpawnBoundBox.y);
            if (Vector2.Distance(player.position, new Vector2(asteroidX, asteroidY)) > minimumDistanceToPlayer)
            {
                break;
            }
        }

        GameObject     asteroid       = Instantiate(asteroidPrefab, new Vector3(asteroidX, asteroidY, 0.0f), Quaternion.identity);
        AsteroidScript asteroidScript = asteroid.GetComponent <AsteroidScript>();
        const float    maxRadius      = 5.0f;
        const float    minRadius      = 2.0f;
        float          asteroidRadius = UnityEngine.Random.Range(minRadius, maxRadius);

        asteroidScript.Initialize(asteroidRadius);
    }