Menu
CoddyTech

Recap: Orbiting Moon

Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 36 of 85.

This recap puts the chapter together: a child that follows its parent with no code, a turn every frame, and a scale that grows toward a limit.

challenge icon

Challenge

Medium

Write the planet's script; the moon, its child, follows by itself.

  1. In Update(), spin the planet around y at spin degrees a second.
  2. While Space is held, grow a float size field from 1 toward 2 at grow a second with Mathf.MoveTowards.
  3. Set transform.localScale = Vector3.one * size;.

Press Play and hold Space: the planet grows and the moon swings wider. Then Check.

Try it yourself

using UnityEngine;

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

    void Update()
    {
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Unity Scripting Basics

Practice on your own: Unity playground