AsteroidSpawner.CreateNewAsteroid C# (CSharp) Method

CreateNewAsteroid() public method

public CreateNewAsteroid ( ) : void
return void
    void CreateNewAsteroid()
    {
        // If we're not currently spawning asteroids, bail out
        if (spawnAsteroids == false) {
            return;
        }

        // Randomly select a point on the surface of the sphere
        var asteroidPosition = Random.onUnitSphere * radius;

        // Scale this by the object's scale
        asteroidPosition.Scale(transform.lossyScale);

        // And offset it by the asteroid spawner's location
        asteroidPosition += transform.position;

        // Create the new asteroid
        var newAsteroid = Instantiate(asteroidPrefab);

        // Place it at the spot we just calculated
        newAsteroid.transform.position = asteroidPosition;

        // Aim it at the target
        newAsteroid.transform.LookAt(target);
    }