Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class Planet : MonoBehaviour {
- private float alpha; //will use for cos & sin (as angle)
- private float distance;//distance from center
- private float Rotation;//rotation angle
- private float currentTime;//Time start when Instantiated
- //input values
- public float speed;
- public Vector2 RotationValues;
- public Vector2 distanceValues;
- public Vector2 sizeValues;
- void Start () {
- //Initialize with Random rotation & distance & size
- //Random Rotation between -2 & 2
- Rotation = Random.Range(RotationValues.x, RotationValues.y);
- //Random distance between -1 & 2
- distance = Random.Range(distanceValues.x, distanceValues.y);
- //Random Size between 0.2f & 0.7f
- var Size = Random.Range(sizeValues.x, sizeValues.y);
- //Set localScale with random size
- transform.localScale = new Vector3(Size, Size, Size);
- //calculating current time by subtraction Time.time and lastTime
- currentTime = Time.time - Generator.lastTime;
- //GetComponent<MeshRenderer>().material.color = new Color(Random.value, Random.value, Random.value); //Random Color
- }
- void Update () {
- //Timer
- currentTime += Time.deltaTime;
- var X = (distance * Mathf.Cos(currentTime)); //X
- var Y = (distance * Mathf.Sin(currentTime)); //Y
- var R = (Rotation * Mathf.Cos(currentTime)); //Rotation
- //give earth from generator class
- var Earth = Generator.Earth;
- transform.position = Earth.transform.position + (new Vector3(X, R, Y));// RotateAround Earth
- }
- }
- using UnityEngine;
- using System.Collections;
- public class Generator : MonoBehaviour {
- public GameObject prefab;
- public static GameObject Earth;
- public static float lastTime;
- public int numerOfSatellites;
- void Start() {
- Earth = GameObject.FindGameObjectWithTag("MainPlanet");//Find Earth
- for (int i = 1; i <= numerOfSatellites; i++) {
- lastTime = Time.time;
- GameObject sat = Instantiate(prefab, Earth.transform.position, Quaternion.identity);
- Physics2D.IgnoreCollision(sat.GetComponent<CircleCollider2D>(), Earth.GetComponent<CircleCollider2D>());
- } }
- }
- void Update () {
- //Timer
- currentTime += Time.deltaTime;
- var X = (distance * Mathf.Cos(currentTime)); //X
- var Y = (distance * Mathf.Sin(currentTime)); //Y
- var R = (Rotation * Mathf.Cos(currentTime)); //Rotation
- //give earth from generator class
- var Earth = Generator.Earth;
- transform.position = Earth.transform.position + (new Vector3(X, R, Y));// RotateAround Earth
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement