Recap: Bullet Time
Part of the Building Real Games section of Coddy's Unity journey. Lesson 36 of 56.
Challenge
MediumGive the game bullet time, powered by a focus meter. Write BulletTime.cs on the Game object. The Inspector sets slowScale (0.2), maxFocus (2), recharge (0.5) and focusBar, the filled Image at the top of the screen. Keep the meter in the float focus.
focusstarts full, atmaxFocus.- While Space is held and
focusis above 0, the game runs atslowScale, with the physics step shrunk by the same factor from 0.02, andfocusdrains by 1 every real second, never below 0. - The rest of the time, the game runs at normal speed with a physics step of 0.02. An empty meter ends bullet time even while Space stays down.
- While Space is not held,
focusrefills byrechargeevery real second, up tomaxFocus. - Every frame, the bar's
fillAmountisfocusdivided bymaxFocus.
Press Play, hold Space and watch the rain, then Check.
Try it yourself
using UnityEngine;
using UnityEngine.UI;
public class BulletTime : MonoBehaviour
{
public float slowScale = 0.2f;
public float maxFocus = 2f;
public float recharge = 0.5f;
public Image focusBar;
float focus;
void Update()
{
}
}
All lessons in Building Real Games
2Buttons and Screens
Buttons and onClickLambdasWiring in the InspectorPanels On and OffHealth BarsRecap: Upgrade Shop5Saving with PlayerPrefs
Save a NumberLoad with a DefaultHigh ScoreSave SettingsRecap: Coins in the Bank3The Game Manager
One Script Runs the GameThe SingletonGame StatesSwitching on the StateRecap: Round Manager6Project: Endless Runner
Three LanesObstacles Ahead9The New Input System
Two Input SystemsKeyboard and MousePressed This FrameInput ActionsRecap: Input Swap