Adding an afterburner
Objective: Provide a player speed boost while holding the left shift key down.
To add a visual effect for the afterburner, duplicate the Thruster, naming it Afterburner. Set the Afterburner to inactive by clicking on the check box near its name. Reduce the scale of the Thruster to (X 0.5, Y 0.5, Z 0.5).
In the Player script, three new variables are required.
Define the GameObject variables in void Start().
In void Update() within the Player script we add the code below. The if statement checks for the LeftShift key to pressed. To avoid crazy speeds the bool variable _afterburnersOn is checked to see if afterburners are already on. If they are not on the _velocityMultiplier for movement is multiplied by two, _afterburner animation is set to active, _thruster animation is turned off, and the bool is set to true. If the left shit key is not down in the frame then the _afterburnerOn is checked to see if the afterburner is engaged, and if it is true then the _velocityMultiplier is divided by two, _afterburner animation is set to inactive, _thruster animation is turned on, and the bool is set to false.
Below is the movement code showing how the _velocityMultiplier is used to increase the speed.