IEnumerator Generate() { while (true) { GameObject comet = Instantiate <GameObject>(model); CelestialOrbit orbit = comet.GetComponent <CelestialOrbit>(); if (orbit == null) { orbit = comet.AddComponent <CelestialOrbit>(); } comet.transform.parent = transform; comet.transform.localScale = Vector3.one * Random.Range(sizeRange.x, sizeRange.y); orbit.eccentricity = Random.Range(eccentricityRange.x, eccentricityRange.y); orbit.periapsis = Random.Range(semiMajorAxisRange.x, semiMajorAxisRange.y); orbit.period = Random.Range(periodRange.x, periodRange.y); orbit.limits = new Vector2(-360, 360); orbit.meanAnomaly = -360f; orbit.longitude = Random.Range(-180, 180); orbit.inclination = Random.Range(-180, 180); orbit.argument = Random.Range(-180, 180); orbit.ResetSimulation(); comet.SetActive(true); DestroyOnDisable destroy = comet.AddComponent <DestroyOnDisable>(); orbit.OnOrbitEnd.AddListener(destroy.OnDisable); yield return(new WaitForSeconds(rate)); } }
void Start() { System.DateTime time = System.DateTime.Now; seconds.meanAnomaly = (float)time.Millisecond / 1000f * 360f; minutes.meanAnomaly = (float)time.Second / 60f * 360f; hours.meanAnomaly = (float)time.Minute / 60f * 360f; days.meanAnomaly = (float)time.Hour / 24f * 720f; seconds.ResetSimulation(); minutes.ResetSimulation(); hours.ResetSimulation(); days.ResetSimulation(); }