Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Planet : MonoBehaviour {
  6. private float alpha; //will use for cos & sin (as angle)
  7. private float distance;//distance from center
  8. private float Rotation;//rotation angle
  9. private float currentTime;//Time start when Instantiated
  10. //input values
  11. public float speed;
  12. public Vector2 RotationValues;
  13. public Vector2 distanceValues;
  14. public Vector2 sizeValues;
  15.  
  16.  
  17. void Start () {
  18. //Initialize with Random rotation & distance & size
  19.  
  20. //Random Rotation between -2 & 2
  21. Rotation = Random.Range(RotationValues.x, RotationValues.y);
  22. //Random distance between -1 & 2
  23. distance = Random.Range(distanceValues.x, distanceValues.y);
  24. //Random Size between 0.2f & 0.7f
  25. var Size = Random.Range(sizeValues.x, sizeValues.y);
  26. //Set localScale with random size
  27. transform.localScale = new Vector3(Size, Size, Size);
  28.  
  29. //calculating current time by subtraction Time.time and lastTime
  30. currentTime = Time.time - Generator.lastTime;
  31.  
  32. //GetComponent<MeshRenderer>().material.color = new Color(Random.value, Random.value, Random.value); //Random Color
  33. }
  34.  
  35. void Update () {
  36. //Timer
  37. currentTime += Time.deltaTime;
  38.  
  39. var X = (distance * Mathf.Cos(currentTime)); //X
  40. var Y = (distance * Mathf.Sin(currentTime)); //Y
  41. var R = (Rotation * Mathf.Cos(currentTime)); //Rotation
  42. //give earth from generator class
  43. var Earth = Generator.Earth;
  44. transform.position = Earth.transform.position + (new Vector3(X, R, Y));// RotateAround Earth
  45.  
  46. }
  47. }
  48.  
  49. using UnityEngine;
  50. using System.Collections;
  51.  
  52. public class Generator : MonoBehaviour {
  53. public GameObject prefab;
  54. public static GameObject Earth;
  55. public static float lastTime;
  56. public int numerOfSatellites;
  57.  
  58.  
  59. void Start() {
  60. Earth = GameObject.FindGameObjectWithTag("MainPlanet");//Find Earth
  61. for (int i = 1; i <= numerOfSatellites; i++) {
  62. lastTime = Time.time;
  63. GameObject sat = Instantiate(prefab, Earth.transform.position, Quaternion.identity);
  64. Physics2D.IgnoreCollision(sat.GetComponent<CircleCollider2D>(), Earth.GetComponent<CircleCollider2D>());
  65. } }
  66. }
  67.  
  68. void Update () {
  69.  
  70. //Timer
  71. currentTime += Time.deltaTime;
  72.  
  73. var X = (distance * Mathf.Cos(currentTime)); //X
  74. var Y = (distance * Mathf.Sin(currentTime)); //Y
  75. var R = (Rotation * Mathf.Cos(currentTime)); //Rotation
  76.  
  77. //give earth from generator class
  78. var Earth = Generator.Earth;
  79. transform.position = Earth.transform.position + (new Vector3(X, R, Y));// RotateAround Earth
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement