With my facts supported by the official Unity website (Unity3d, 2015), firstly, importing any assets into Unity. It's a simply drag and drop affair from your PC's desktop into your project's content window, or by clicking 'Assets' at the top of the screen, then 'Import Assets'. However make sure your sound file is has a .wave, .aif, .mp3 or .off file extension for it to be compatible! When your audio is finally inside Unity, it will be replace by an 'Audio Clip' file (Docs.unity3d.com, 2015), which basically holds all the original sound data that you imported, with it being something an Audio Source object would use.
My own screenshot of the toolbar option in Unity |
Now we have playing sound, which as taken from (Docs.unity3d, 2015), you can use the simple line of code "public void Play(ulong delay = 0);" in C#. All it does is plays your sound after the specified delay, so in this case the sound will play instantly as the delay is set to 0 seconds! Here's an example of code from the same source giving the programmer specific control over the playing of their sound: "using UnityEngine;
using System.Collections; [RequireComponent(typeof(AudioSource))] public class ExampleClass : MonoBehaviour { void Start() { AudioSource audio = GetComponent<AudioSource>(); audio.Play(); audio.Play(44100); }}"
Next is triggering the sound, where if you remember back to when I talked about collision that's one of the ways sound can be implemented here too. This can be performed by a simple trigger box and collision method, as sourced by (aldonaletto, 2015), from the Unity help forums (and not the official Unity blog). All you have to do is create a trigger volume that the player can collide with, then using this function code it will trigger the sound to play once: "
- function OnTriggerEnter(other: Collider){
- if (!audio.isPlaying){
- audio.Play();
- }
- }
Now onto creating the sound dynamically, this can even be something as simple as playing sound from either the left or right speaker to make a game feel more immersive. It essentially means to play sounds and music in a creative or different way, so maybe play music inside a far-off caravan, enticing the player over to go and see it. Games in Unity should consider using an AudioSource GameObject that's attached to another object in-game, which (with information from (AudioSource, 2015)), is very useful to play background noises in games, and is especially useful when attached to the scene's camera object to help create looping ambient sound effects.
Manipulating volume just means the volume of your sound will be adjusted in your game, so a quiet whisper in a hedge will have a pretty low int value in your code, whereas a spooky jumpscare to freak out the player will set it abnormally high. This can be implemented by code, as used by (Kryptos, 2015) from Unity Answers. "
// setting volume to zero
audio.volume = 0;
// or mute
audio.mute = true;
A picture of the Audio Mixer tab open in Unity, from (AudioMixer, 2015) |
No comments:
Post a Comment