Menu
CoddyTech

Recap: Elevator

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

This recap puts the chapter together: fields the Inspector sets, kept private with [SerializeField], and read every frame in Update().

challenge icon

Challenge

Easy

Write the elevator's script: it rises to the top and stops there.

  1. Add two fields, speed and top, as [SerializeField] private float. The Inspector sets them to 2 and 5.
  2. In Update(), while transform.position.y is below top, add new Vector3(0, speed * Time.deltaTime, 0) to transform.position.

Press Play: the elevator rises to a height of 5 and stays. Then Check.

Try it yourself

using UnityEngine;

public class Lift : MonoBehaviour
{
    // speed and top: private, set in the Inspector

    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