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
EasyMake the cube a charge jumper.
- While
Input.GetButton("Jump")(Space) is held, growchargeby 1 a second, never past2. - On
Input.GetButtonUp("Jump"), set the cube's y to0.5f + charge * power, thenchargeto 0. - While its y is above
0.5f, move it down atfallunits 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()
{
}
}
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