Advertisement
shadowplaycoding

P011_SolarSystem

Apr 29th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.85 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))
  33.         {
  34.             Galaxy.GalaxyInstance.MoveSelectionIcon(hit);
  35.  
  36.             if (Input.GetMouseButtonDown(0) && Galaxy.GalaxyInstance.galaxyView == true)
  37.             {
  38.                 Star star = Galaxy.GalaxyInstance.ReturnStarFromGameObject(hit.transform.gameObject);
  39.                 starPosition = hit.transform.position;
  40.                 Debug.Log("This Star is Called: " + star.starName + "\n" + "It Has " + star.numberOfPlanets + " Planets");
  41.  
  42.                 Galaxy.GalaxyInstance.DestroyGalaxy();
  43.                 CreateSolarSystem(star);
  44.             }
  45.         }
  46.         else
  47.         {
  48.             Galaxy.GalaxyInstance.selectionIcon.SetActive(false);
  49.         }
  50.  
  51.     }
  52.  
  53.     // This method creates the solar system view after a star is clicked on in the galaxy view
  54.     public void CreateSolarSystem(Star star)
  55.     {
  56.         CameraController.cameraController.ResetCamera();
  57.  
  58.         Galaxy.GalaxyInstance.selectionIcon.SetActive(false);
  59.  
  60.         Random.InitState(Galaxy.GalaxyInstance.seedNumber);
  61.  
  62.         Galaxy.GalaxyInstance.galaxyView = false;
  63.  
  64.         SpaceObjects.CreateSphereObject(star.starName, Vector3.zero, this.transform);
  65.  
  66.         for (int i = 0; i < star.planetList.Count; i++)
  67.         {
  68.             Planet planet = star.planetList[i];
  69.  
  70.             Vector3 planetPos = PositionMath.PlanetPosition(i);
  71.  
  72.             SpaceObjects.CreateSphereObject(planet.planetName, planetPos, this.transform);
  73.  
  74.             GameObject orbit = SpaceObjects.CreateOrbitPath(OrbitSpritePrefab, planet.planetName + " Orbit", i + 1, this.transform);
  75.         }
  76.  
  77.         galaxyViewButton.interactable = true;
  78.  
  79.     }
  80.  
  81.     public void DestroySolarSystem()
  82.     {
  83.         while (transform.childCount > 0)
  84.         {
  85.             Transform go = transform.GetChild(0);
  86.             go.SetParent(null);
  87.             Destroy(go.gameObject);
  88.         }
  89.  
  90.         CameraController.cameraController.MoveTo(starPosition);
  91.         galaxyViewButton.interactable = false;
  92.  
  93.     }
  94.  
  95.     /*
  96.    Copyright Shadowplay Coding 2017 - see www.shadowplaycoding.com for licensing details
  97.    Removing this comment forfits any rights given to the user under licensing.
  98.    */
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement