예제 #1
0
    void PopulateRoundGalaxy()
    {
        int failCount = 0;

        for (int i = 0; i < Galaxy.NumberOfStars; i++)
        {
            Vector3 position = PositionMaths.RandomPolarPosition(Galaxy.MinimumRadius, Galaxy.MaximumRadius);
            float   rad      = Galaxy.MinDistanceBetweenStars;


            Physics.SyncTransforms();
            bool collision = Physics.CheckSphere(position, rad);

            if (!collision)
            {
                string     name       = Galaxy.Stars[i].Name;
                GameObject starObject = SpaceObjects.CreateSphereObject(name, position, this.transform);
                failCount = 0;
            }
            else
            {
                failCount++;

                if (failCount > Galaxy.NumberOfStars)
                {
                    Debug.LogError("Could not fit all the stars in the Galaxy! Try changing the settings!");
                    break;
                }

                i--;
            }
        }
    }
예제 #2
0
    void PopulateRoundGalaxy()
    {
        int failCount = 0;

        for (int i = 0; i < Galaxy.NumberOfStars; i++)
        {
            Vector3 position = PositionMaths.RandomPolarPosition(Galaxy.MinimumRadius, Galaxy.MaximumRadius);

            Collider[] positionCollider = Physics.OverlapSphere(position, Galaxy.MinDistanceBetweenStars);

            if (positionCollider.Length == 0)
            {
                Star starData = new Star("Star " + i, Random.Range(1, 10));
                Debug.Log("Created " + starData.Name + " with " + starData.NumberOfPlanets + " Planets");

                GameObject starObject = SpaceObjects.CreateSphereObject(starData.Name, position, this.transform);
                failCount = 0;
            }
            else
            {
                i--;
                failCount++;
            }

            if (failCount > Galaxy.NumberOfStars)
            {
                Debug.LogError("Could not fit all the Stars into the Galaxy! Try changing settings");
                break;
            }
        }
    }