Advertisement
shadowplaycoding

P008_SolarSystem

Apr 29th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class SolarSystem : MonoBehaviour {
  6.  
  7.     public static SolarSystem SolarSystemInstance;
  8.  
  9.     public Button galaxyViewButton;
  10.  
  11.     void OnEnable()
  12.     {
  13.         SolarSystemInstance = this;
  14.         galaxyViewButton.interactable = false;
  15.     }
  16.  
  17.     // Use this for initialization
  18.     void Start () {
  19.    
  20.     }
  21.    
  22.     // Update is called once per frame
  23.     void Update () {
  24.  
  25.         Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
  26.         RaycastHit hit = new RaycastHit();
  27.  
  28.         if (Physics.Raycast(mouseRay, out hit) && Input.GetMouseButtonDown(0))
  29.         {
  30.             Star star = Galaxy.GalaxyInstance.ReturnStarFromGameObject(hit.transform.gameObject);
  31.             Debug.Log("This Star is Called: " + star.starName + "\n" + "It Has " + star.numberOfPlanets + " Planets");
  32.  
  33.             Galaxy.GalaxyInstance.DestroyGalaxy();
  34.             CreateSolarSystem(star);
  35.         }
  36.  
  37.     }
  38.  
  39.     // This method creates the solar system view after a star is clicked on in the galaxy view
  40.     public void CreateSolarSystem(Star star)
  41.     {
  42.         Random.InitState(Galaxy.GalaxyInstance.seedNumber);
  43.  
  44.         Galaxy.GalaxyInstance.galaxyView = false;
  45.  
  46.         SpaceObjects.CreateSphereObject(star.starName, Vector3.zero, this.transform);
  47.  
  48.         for (int i = 0; i < star.planetList.Count; i++)
  49.         {
  50.             Planet planet = star.planetList[i];
  51.  
  52.             Vector3 planetPos = PositionMath.PlanetPosition(i);
  53.  
  54.             SpaceObjects.CreateSphereObject(planet.planetName, planetPos, this.transform);
  55.         }
  56.  
  57.         galaxyViewButton.interactable = true;
  58.  
  59.     }
  60.  
  61.     public void DestroySolarSystem()
  62.     {
  63.         while (transform.childCount > 0)
  64.         {
  65.             Transform go = transform.GetChild(0);
  66.             go.SetParent(null);
  67.             Destroy(go.gameObject);
  68.         }
  69.  
  70.         galaxyViewButton.interactable = false;
  71.  
  72.     }
  73.  
  74.     /*
  75.    Copyright Shadowplay Coding 2017 - see www.shadowplaycoding.com for licensing details
  76.    Removing this comment forfits any rights given to the user under licensing.
  77.    */
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement