Advertisement
shadowplaycoding

P015_SpaceObjects

Apr 29th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. public class SpaceObjects {
  6.  
  7.     // This method creates a sphere object whether that be a planet or star.
  8.     public static GameObject CreateSphereObject(string name, Vector3 position, Transform parent = null)
  9.     {
  10.         GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
  11.         sphere.name = name;
  12.         sphere.transform.position = position;
  13.         sphere.transform.parent = parent;
  14.         sphere.isStatic = true;
  15.  
  16.         CreateNamePlate(sphere);
  17.  
  18.         return sphere;
  19.     }
  20.  
  21.     // This method creates orbital graphics for planets in the solar system.
  22.     public static GameObject CreateOrbitPath(GameObject orbitSprite, string name, int orbitNumber, Transform parent = null)
  23.     {
  24.         GameObject orbit = GameObject.Instantiate(orbitSprite);
  25.        
  26.         orbit.name = name;
  27.         orbit.transform.localScale = orbit.transform.localScale * orbitNumber;
  28.         orbit.transform.SetParent(parent);
  29.  
  30.         return orbit;
  31.     }
  32.  
  33.     public static void CreateNamePlate(GameObject go)
  34.     {
  35.         TextMesh nameText = new GameObject(go.name + " Name Plate").AddComponent<TextMesh>();
  36.         nameText.transform.SetParent(go.transform);
  37.         nameText.text = go.name;
  38.         nameText.transform.localPosition = new Vector3(0, -1.2f, 0);
  39.         nameText.anchor = TextAnchor.MiddleCenter;
  40.         nameText.alignment = TextAlignment.Center;
  41.         nameText.color = Color.white;
  42.         nameText.fontSize = 10;
  43.         nameText.gameObject.isStatic = true;
  44.     }
  45.  
  46.     /*
  47.     Copyright Shadowplay Coding 2017 - see www.shadowplaycoding.com for licensing details
  48.     Removing this comment forfits any rights given to the user under licensing.
  49.     */
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement