Difference between revisions of "Audio"
(Created page with "=Playing only in a certain area= Attach an Audio Source component to something you’d like to have be the center of the area the sound covers. Add the audio file you’d lik...") |
(No difference)
|
Revision as of 11:18, 28 November 2017
Playing only in a certain area
Attach an Audio Source component to something you’d like to have be the center of the area the sound covers. Add the audio file you’d like to have play to the AudioClip field and adjust the volume as necessary. When you select a game object with an Audio Source, in Scene view it will show blue wireframe sphere with dots in some places, moving these dots will make the area of the audio larger or smaller.
Sound Effects with actions
Add an Audio Source to the object you’d like the sound effects to come from (it can be attached to the player). Then start making a script to make a sound get activated. You can leave the AudioClip field of the Audio Source blank for the object and have the clip be a variable determined in the script. You need another variable for where the audio will be coming from, and if you are putting the script directly on the object with the source, you can do “source = GetComponent<AudioSource>();” whenever the object wakes up, as in put it in
void Awake(){ //in here }
After that you can just do “source.PlayOneShot(audioclip,0.2f);” where audioclip is the AudioClip object to be played. Using PlayOneShot that will play your AudioClip just once at a volume between 0 and 1 (0 being silent and 1 being full volume).