Advertisement
shadowplaycoding

P006_SolarSystem

Apr 29th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 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.         SpaceObjects.CreateSphereObject(star.starName, Vector3.zero, this.transform);
  43.  
  44.         for (int i = 0; i < star.planetList.Count; i++)
  45.         {
  46.             Planet planet = star.planetList[i];
  47.  
  48.             Vector3 planetPos = PositionMath.PlanetPosition(i);
  49.  
  50.             SpaceObjects.CreateSphereObject(planet.planetName, planetPos, this.transform);
  51.         }
  52.  
  53.         galaxyViewButton.interactable = true;
  54.  
  55.     }
  56.  
  57.     public void DestroySolarSystem()
  58.     {
  59.         while (transform.childCount > 0)
  60.         {
  61.             Transform go = transform.GetChild(0);
  62.             go.SetParent(null);
  63.             Destroy(go.gameObject);
  64.         }
  65.  
  66.         galaxyViewButton.interactable = false;
  67.  
  68.     }
  69.  
  70.     /*
  71.    Copyright Shadowplay Coding 2017 - see www.shadowplaycoding.com for licensing details
  72.    Removing this comment forfits any rights given to the user under licensing.
  73.    */
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement