38) Add a sound asset.
Download the explosion sound:
here
Import the sound into Unity by dragging and dropping the file into the Project Panel.
Most assests like images and sounds can be imported this way.
39) Add an explosion audio source to the mines
Select any one of the mine prefab objects.
In the Inspector, select AddComponent->Audio->AudioSource.
Drag the Explosion audio clip asset into the Audio Clip field in the AudioSource.
Click "Apply" in the pre-fab bar at the top of the Inspector to add that AudioSource to all mines.
40) Play the explosion on player death.
In the OnTrigger function of the PlayerMovement script, grab the AudioSource component from the trigger collider GameObject and then play its AudioClip.
Get the completed updated example PlayerMovement script:
here.
Note that this method has been commented out in that script because...
This method doesn't work well since the sound comes from the mine which sounds off when the player is respawned somewhere else. So...
41) Use an AudioClip local to PlayerMovement instead.
Add a public AudioClip to PlayerMovement.
Play that AudioClip at the player's position after respawn.
Make sure to drag the explosion audio asset onto the public property in the Inspector.
42) Create the GUIController
Select GameObject->Create Empty from the toolbar to make an empty GameObject.
Name it "GUIController."
Tag it as "GUIController." (You will have to create a new tag as we've done before.)
Add a new script named GUIController.
43) Write the GUIController script.
GUI stuff is done in the overridden OnGUI function.
Create a "background box" for the start button positioned in the middle of the screen.
Create the start button itself, setting a private m_bGameActive bool to true when pushed.
Make the GUI not draw if the game is active.
Add functions to access and reset the m_bGameActive variable.
Get the completed example GUIController script:
here.
44) Lock game updates when GUI is active.
Edit the PlayerMovement script to immediately return from FixedUpdate if the game is inactive.
The GUIController should be found and locally cached in the Start function using GameObject.FindGameObjectWithTag.
If you downloaded the sample updated PlayerMovement script from step #40, just uncomment the lines at 10, 20, 29, and 30.
Update the MovingWall script in a similar way.
Get the updated sample MovingWall script:
here.