예제 #1
0
    //
    // spawn an asteroid so it isn't on top of a ship
    public void SpawnAsteroidAwayFromShip(int size)
    {
        if (m_playfield == null)
        {
            Debug.LogError("game should have a playfield");
            return;
        }


        // create a new asteroid from prefab
        Asteroid asteroid = Instantiate(asteroidPrefabs[size]) as Asteroid;

        // find a random position away from the ship
        Vector3 shipPosition = new Vector3();

        if (m_ship != null)
        {
            shipPosition = m_ship.transform.position;
        }
        Vector3 position;

        do
        {
            position = m_playfield.GetRandomLocation();
        } while ((position - shipPosition).magnitude < minDistance);

        // set the asteroid's position in the play field
        asteroid.transform.position = position;
        asteroid.transform.parent   = transform;
        asteroid.game            = this;
        asteroid.speedMultiplier = m_speedMultiplier;
        asteroid.size            = size;
        // add to the list
        m_asteroids.Add(asteroid);
    }