Exemple #1
0
        public void CreateGalaxy()
        {
            galaxyView = true;

            Random.InitState(seedNumber);
            starToObjectMap = new Dictionary <Star, GameObject>();

            int failCount = 0;

            for (int i = 0; i < numberOfStars; i++)
            {
                Star starData = new Star("Star " + i, Random.Range(2, 7));
                //Debug.Log("Created " + starData.starName + " with " + starData.numberOfPlanets + " planets");
                CreatePlanetData(starData);

                Vector3 position = PositionMath.RandomPosition(minimumRadius, maximumRadius);

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

                if (positionCollider.Length == 0)
                {
                    GameObject star = SpaceObjects.CreateSphereObject(starData.starName, position, this.transform);
                    starToObjectMap.Add(starData, star);
                    failCount = 0;
                }
                else
                {
                    i--;
                    failCount++;
                }

                if (failCount > numberOfStars)
                {
                    Debug.LogError("Could not fit all stars in the galaxy. Consider smaller distance between stars!");
                    break;
                }
            }
        }