using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; /// /// Rotates this object around the specified center transform, as well as around itself on the specified axis. /// Used in the ZED planetarium sample on each planet/moon to make it orbit the sun and also spin on its own axis. /// public class PlanetMover : MonoBehaviour { /// /// The transform this object revolves around. Always the Sun in the ZED planetarium sample, except for the moon. /// [Tooltip("The transform this object revolves around. Always the Sun in the ZED planetarium sample, except for the moon.")] public Transform center; /// /// Degrees per second this object moves around its orbit. /// [Tooltip("Degrees per second this object moves around its orbit.")] public float speedRevolution = 10; /// /// The axis of rotation around its poles, ie, the direction from the planet's south pole to the north pole. /// [Tooltip("The axis of rotation around its poles, ie, the direction from the planet's south pole to the north pole. ")] public Vector3 axis = Vector3.up; /// /// Degrees per second the object rotates on its own axis. /// [Tooltip("Degrees per second the object rotates on its own axis. ")] public float speed = 10.0f; /// /// Axis the planet revolves around on its orbit. /// private Vector3 dir; private void Start() { dir = center.up; //Get the axis of rotation from the object we're rotating. } // Update is called once per frame void Update () { transform.RotateAround(center.position, center.TransformDirection(dir), Time.deltaTime * speedRevolution); //Rotating around the sun (orbit). transform.Rotate(axis, speed*Time.deltaTime, Space.Self); //Rotating around its own axis (night/day). } }