Having trouble with playing a sound
I'm trying to get a sound effect to play when the player swings a sword. Following a Brackeys tutorial, I got an audio manager set up. When I swung the sword, the console reports that the proper functions were called and the sound was played, yet I didn't hear anything. The volume is maxed, it's set to 2d. I did everything I could find. So I did some investigating and recorded the game audio in audacity. Turning up the audio, I found out it was, in fact, playing sound every time I swung the sword, but it was a weird clicking sound, as if the audio stopped the second it got played. I have no idea why this is happening.
Answer by tylerdtrudeau · Mar 05, 2021 at 07:33 PM
I dont have alot of experience with sound stuff, but just to ask the obvious. Have you tried playing the sound clip somewhere else like say Windows Media Player to see if the sound file is working properly? Also have you tried downloading a different sound effect from somewhere like opengameart.org and trying that file to see if that one works?
I have, yes. The sound plays fine everywhere else, including the editor. It just doesn't work in-game. I went ahead and tried throwing a different sound on it, but that didn't work.
Answer by ahmadgml32 · Mar 05, 2021 at 09:09 PM
u have 3 function for playing sound in unity 1- playing sound on awake without scripting from "play on awake" bool from audio source it self 2- AudioSource.Play(); which could be useful if playing sound just one or each period 3-ِfinally AudioSource.PlayOneShot(audioClipHere); this could be used for playing sound so fast like shooting weapons or something
now u have working sounds but it looks terrible when playing a lot so u can fix this using this simple line which randomly select pitch value
if if it didn't played at all go to edit/projectSetting/Audio/Disable Unity Audio make it false hope this works
public float factor = 0.2f;
public AudioSource audioSource;
public AudioClip clip;
private void Update()
{
audioSource.PlayOneShot(clip);
//or use this AudioSource.PlayOneShot(clip, volume Value Here);
float audioPitch = Random.Range(Time.timeScale, Time.timeScale + factor);
audioSource.pitch = audioPitch;
}
if it didn't work yet increase global volume from audio setting like disable unity audio hope this fix your issues.
I not having trouble playing the sound, per say, the sound is technically playing. It's just messed up when played in-game. I've already made sure there wasn't any volume issues as well.
so audio stutters or what?? if it did just change doppler level from audio source what that does is sound changes depending on the distance between the audio listener and the audio source if it too close audio stutters
also If you speak arabic it is better to speak it to make it easier for you and me