Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class Univers : MonoBehaviour {
- public int nbrOfSystem = 1;
- [System.Serializable]
- public class SolarSystem
- {
- public string nameOfSystem;
- public int planetsOnSystem;
- public Vector3 sunOfSystem;
- public List<GameObject> planets = new List<GameObject>();
- public void Generate()
- {
- GameObject sun = Instantiate(Resources.Load("Solar/Sun"), sunOfSystem, Quaternion.identity) as GameObject;
- sun.name = "Sun : " + nameOfSystem;
- sun.transform.parent = GameObject.Find("Univers").transform;
- for (int i = 0; i < planetsOnSystem; i++)
- {
- Vector3 planetPos = new Vector3(Random.Range(sunOfSystem.x - 200, sunOfSystem.x - 50), sunOfSystem.y, Random.Range(sunOfSystem.z - 200, sunOfSystem.z - 50));
- GameObject planet = Instantiate(Resources.Load("Solar/Planet"), planetPos, Quaternion.identity) as GameObject;
- planet.transform.parent = sun.transform;
- planet.GetComponent<Planet>().Init(sun.transform);
- planets.Add(planet);
- }
- }
- }
- public List<SolarSystem> solarSystems = new List<SolarSystem>();
- // Use this for initialization
- void Start () {
- float x = 0;
- float y = 0;
- float z = 0;
- for (int i = 0; i < nbrOfSystem; i++)
- {
- SolarSystem _solar = new SolarSystem();
- _solar.nameOfSystem = "System " + Random.Range(1, 9) + "Z" + Random.Range(1, 999);
- _solar.planetsOnSystem = Random.Range(1, 20);
- _solar.sunOfSystem = new Vector3(x, y, z);
- x += Random.Range(-3000, 3000);
- y += Random.Range(-3000, 3000);
- z += Random.Range(-3000, 3000);
- _solar.Generate();
- solarSystems.Add(_solar);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement