Recap: Charge Jump
Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 16 of 67.
Challenge
EasyMake the cube a charge jumper:
- While the Jump button (Space) is held,
chargegrows by 1 every second, but never past 2. - When Jump is released, the cube jumps: its y becomes
0.5 + charge * power, andchargegoes back to 0. - While the cube is above the ground (y = 0.5), it falls at
fallunits 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
1Your First Script
Hello, UnityPlace the CubeMove Every FrameTurn Every SecondSteer with the KeysRecap: Drive the Cube4Vectors
Adding VectorsDirectionsLocal and World SpaceDiagonal SpeedDistance Between ThingsVector3 Is a StructRecap: Drone Pilot7Project: Catch the Star
The CatcherA Falling Star5Transforms and Hierarchy
Parents and ChildrenScaleLook At ThingsMove Toward a PointRecap: Orbiting Moon