Game Development Reference
In-Depth Information
audio.volume = 1.0;
audio.PlayOneShot(getKeySound);
b_hasKey = true;
Destroy (hit.gameObject);
}
}
9. Inside if (hit.collider.tag == "Door") {} , add the highlighted code:
if (hit.collider.tag == "Door") {
if (b_hasKey) {
audio.volume = 1.0;
audio.PlayOneShot(doorOpenSound);
//If we had Key and hit door the door will open
hit.gameObject.renderer.material.mainTexture =
doorOpenTexture;
//wait for 1 second and destroy our character
yieldWaitForSeconds(1);
Destroy (gameObject);
//We close the door
hit.gameObject.renderer.material.mainTexture =
doorCloseTexture;
//Show Restart Button
restartButton.enabled = true;
}
}
And for the last thing before we go back to Unity, put this line at the end
of the code to basically force the script to add an AudioSource script to
CharacterController_2D.js :
@scriptRequireComponent (AudioSource)
10. Then, we go back to Unity, and click on the Player to open the Inspector . We
will see Door Open Sound , Get Key Sound , and Jump Sound . Then, we assign the
sounds to these as follows:
Door Open Sound : doorOpen.wav
Get Key Sound : getKey.aiff
Jump Sound: Jump.wav
11. Next, we need to add an Audio Source script to be able to use our sound for the
Player . This is because we already atached this script to the game object, so Unity
doesn't add it for us.
 
Search WWH ::




Custom Search