Menu
CoddyTech

Recap: Charge Jump

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

This recap puts the chapter together: a key held, a key released, and a value that grows every frame by Time.deltaTime, kept below a limit.

challenge icon

Challenge

Easy

Make the cube a charge jumper.

  1. While Input.GetButton("Jump") (Space) is held, grow charge by 1 a second, never past 2.
  2. On Input.GetButtonUp("Jump"), set the cube's y to 0.5f + charge * power, then charge to 0.
  3. While its y is above 0.5f, move it down at fall units a second.

Press Play, hold Space two seconds and let go: the cube leaps and falls back. Then Check.

Try it yourself

using UnityEngine;

public class ChargeJump : MonoBehaviour
{
    public float power = 1f;
    public float fall = 1f;
    float charge = 0f;

    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