Esempio n. 1
0
    public Planetoid CreateStarSystem()
    {
        // Set up a "Star System" Game object at a random position on screen
        GameObject starSystemGO = new GameObject("StarSystem");
        float      starSize     = Random.Range(dist * 0.2f, dist) / 5.0f + 0.5f;
        Vector3    newPos       = GetNewPos(starSize);


        starSystemGO.transform.position = newPos;


        // Instantiate system's "star"
        GameObject starGo = Instantiate(
            original: planetPrefab,
            parent: starSystemGO.transform
            );

        starGo.name = "Star";
        starGo.tag  = "star";
        Planetoid starPlanetoid = starGo.GetComponent <Planetoid>();

        starPlanetoid.InitializePlanetoid(
            centerOfGravity: starGo.transform,
            orbitSpeed: 0,
            orbitRadius: 0,
            isRotatingClockwise: false,
            size: starSize
            );

        return(starPlanetoid);
    }
Esempio n. 2
0
    List <Planetoid> AddPlanets(Planetoid parent, int numPlanets, int depth)
    {
        List <Planetoid> planetoids = new List <Planetoid>();

        for (int i = 0; i < numPlanets; i++)
        {
            float      planetSize = Random.Range(parent.size * 0.5f, parent.size * 0.8f);
            GameObject planetGo   = Instantiate(planetPrefab, parent.transform);
            planetGo.transform.parent = parent.transform.root;
            planetGo.name             = "Planet (d" + depth + ")";
            planetGo.tag = "planet";

            Planetoid planetoid = planetGo.GetComponent <Planetoid>();
            planetoid.InitializePlanetoid(
                centerOfGravity: parent.transform,
                orbitSpeed: Random.Range(0.1f, 1f),
                orbitRadius: (planetSize + parent.size) * (2 + i) / depth,
                isRotatingClockwise: (Random.Range(0f, 1f) < 0.3f),
                size: planetSize
                );
            planetoids.Add(planetoid);
        }

        return(planetoids);
    }