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
MediumWrite the planet's script; the moon, its child, follows by itself.
- In
Update(), spin the planet around y atspindegrees a second. - While Space is held, grow a
float sizefield from 1 toward 2 atgrowa second withMathf.MoveTowards. - 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()
{
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Unity Scripting Basics
1C# Basics in Unity
Hello, UnityVariablesDecimals Need an fText in the ConsoleVariables That RememberIf and ElseCompare NumbersRecap: Coin Collector2Make It Move
Place the CubeMove Every FrameTurn Every SecondSteer with the KeysRecap: Drive the Cube5Vectors
Adding VectorsDirectionsLocal and World SpaceDiagonal SpeedDistance Between ThingsVector3 Is a StructRecap: Drone Pilot8GameObjects and Components
References in the InspectorGet a ComponentMissing ComponentsAdd a ComponentRequireComponentShow and HideRecap: Light Switch6Transforms and Hierarchy
Parents and ChildrenHoist the FlagScaleLook At ThingsMove Toward a PointRecap: Orbiting Moon9Project: Catch the Star
The CatcherA Falling StarPractice on your own: Unity playground