Advertisement
shadowplaycoding

P009_SolarSystem

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