Adding the moon orbit

Let's write a script called Orbit that rotates one object, the moon, around another object, the earth. We want to be able to specify its orbital period as the number of earth days for one complete orbit. For the moon, that's 27.3 days. And, like our Spin script, we'll also provide a scalar that converts earth days into game time seconds as shown ahead:

  1. In Hierarchy, select Moon and Add Component, New Script (C-Sharp). Name it Orbit, then press Create and Add.
  2. Double-click on the new script to open it in your code editor.

Write the Orbit class as follows:

File: Orbit.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class Orbit : MonoBehaviour { public Transform aroundBody; public ...

Get Augmented Reality for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.