Menu
CoddyTech

Recap: Charge Jump

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

challenge icon

Challenge

Easy

Make the cube a charge jumper:

  • While the Jump button (Space) is held, charge grows by 1 every second, but never past 2.
  • When Jump is released, the cube jumps: its y becomes 0.5 + charge * power, and charge goes back to 0.
  • While the cube is above the ground (y = 0.5), it falls at fall units per second until it is back down.

The Inspector sets power to 2 and fall to 3. Press Play, hold and release Space, then press Check.

Try it yourself

using UnityEngine;

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

    void Update()
    {
    }
}

All lessons in Unity Scripting Basics