SHARE
TWEET

Univers.cs

a guest Dec 29th, 2015 212 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Univers : MonoBehaviour {
  6.  
  7.     public int nbrOfSystem = 1;
  8.  
  9.     [System.Serializable]
  10.     public class SolarSystem
  11.     {
  12.         public string nameOfSystem;
  13.         public int planetsOnSystem;
  14.         public Vector3 sunOfSystem;
  15.         public List<GameObject> planets = new List<GameObject>();
  16.  
  17.         public void Generate()
  18.         {
  19.             GameObject sun = Instantiate(Resources.Load("Solar/Sun"), sunOfSystem, Quaternion.identity) as GameObject;
  20.             sun.name = "Sun : " + nameOfSystem;
  21.             sun.transform.parent = GameObject.Find("Univers").transform;
  22.  
  23.             for (int i = 0; i < planetsOnSystem; i++)
  24.             {
  25.                 Vector3 planetPos = new Vector3(Random.Range(sunOfSystem.x - 200, sunOfSystem.x - 50), sunOfSystem.y, Random.Range(sunOfSystem.z - 200, sunOfSystem.z - 50));
  26.                 GameObject planet = Instantiate(Resources.Load("Solar/Planet"), planetPos, Quaternion.identity) as GameObject;
  27.                 planet.transform.parent = sun.transform;
  28.                 planet.GetComponent<Planet>().Init(sun.transform);
  29.                 planets.Add(planet);
  30.             }
  31.         }
  32.     }
  33.  
  34.     public List<SolarSystem> solarSystems = new List<SolarSystem>();
  35.  
  36.     // Use this for initialization
  37.     void Start () {
  38.         float x = 0;
  39.         float y = 0;
  40.         float z = 0;
  41.  
  42.         for (int i = 0; i < nbrOfSystem; i++)
  43.         {
  44.             SolarSystem _solar = new SolarSystem();
  45.             _solar.nameOfSystem = "System " + Random.Range(1, 9) + "Z" + Random.Range(1, 999);
  46.             _solar.planetsOnSystem = Random.Range(1, 20);
  47.             _solar.sunOfSystem = new Vector3(x, y, z);
  48.  
  49.             x += Random.Range(-3000, 3000);
  50.             y += Random.Range(-3000, 3000);
  51.             z += Random.Range(-3000, 3000);
  52.  
  53.             _solar.Generate();
  54.             solarSystems.Add(_solar);
  55.         }
  56.     }
  57. }
RAW Paste Data
Top