Advertisement
shadowplaycoding

P010_SolarSystem

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