Beispiel #1
0
    public GameObject generateStarSystem(GameObject baseObject)
    {
        GameObject centreMass = Instantiate(systemCentreMass, new Vector3(0, 0, 0), Quaternion.identity, baseObject != null ? baseObject.transform : gameObject.transform);

        centreMass.name = "CentreMass";

        float currentMinBodySeparation = Random.Range(initialMinBodySeparation, initialMaxBodySeparation);

        int totalPlanets = (int)Random.Range(minPlanetGeneration, maxPlanetGeneration);

        for (int i = 0; i < totalPlanets; i++)
        {
            GameObject planet = Instantiate(planetPrefab, centreMass.transform);
            planet.name = "Planet-" + i;
            OrbitingBody planetBody = ((OrbitingBody)planet.GetComponent(typeof(OrbitingBody)));
            planetBody.minBodySeparation = currentMinBodySeparation;
            planetBody.setupOrbit();

            currentMinBodySeparation = planetBody.getDistanceFromFoci() + minBodySeparation;

            //moon generation for current planet
            float currentMinMoonSeparation = Random.Range(initialMinMoonSeparation, initialMaxMoonSeparation);

            int totalMoons = (int)Random.Range(minMoonGeneration, maxMoonGeneration);

            for (int j = 0; j < totalMoons; j++)
            {
                GameObject moon = Instantiate(moonPrefab, planet.transform);
                moon.name = "Planet-" + i + "-Moon-" + j;
                OrbitingBody moonBody = ((OrbitingBody)moon.GetComponent(typeof(OrbitingBody)));
                moonBody.minBodySeparation = currentMinMoonSeparation;
                moonBody.setupOrbit();

                currentMinMoonSeparation = moonBody.getDistanceFromFoci() + minMoonSeparation;
            }
        }

        return(centreMass);
    }