Menu
CoddyTech

Recap: Orbiting Moon

Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 28 of 67.

challenge icon

Challenge

Medium

The moon is already a child of the planet, 3 units out, and it gets no code: whatever happens to the planet happens to it. Write the planet's script:

  • The planet spins around its y axis at spin degrees per second, carrying the moon around it.
  • While Space is held, the planet grows evenly on every axis: its scale rises by grow per second, from 1 up to 2, and stops at 2.

Watch the moon while the planet grows. Press Play, then Check.

Try it yourself

using UnityEngine;

public class Planet : MonoBehaviour
{
    public float spin = 40f;
    public float grow = 0.5f;

    void Update()
    {
    }
}

All lessons in Unity Scripting Basics