Ok, so a very weird thing is happening. If I wait without clicking anywhere, nothing happens as expected. However, if I fire a few shots (click a few times), or even if I fire one and wait a few seconds, the gun fire sounds will go into a crazy loop and it will sound like a machine gun or fireworks without me clicking at all. I added a breakpoint to the only PlayOneShot call and the strangest thing is it wasn’t being called at all, so I have ABSOLUTELY NO IDEA how it could be that the sound is being played at all, let alone this frequently or how I would even debug beyond this.
I have an AudioSource game object in my hierarchy with an AudioSource attached to it. It is the child of a GameManager game object with a “GameManager” script that has a slot for an AudioSource variable and an AudioClip variable. In the inspector, I assigned the sound I want to play to the AudioClip and this AudioSource game object to the AudioSource slot.
In my GameManager script, in the Update function, I test whether the left mouse button was pressed down and play the sound if it was. This is my code:
bool test = Input.GetMouseButtonDown(0);
if (test) //if shot has been fired
{
if (SHOOTING == currentMode)
{
audioSource.PlayOneShot(gunFire);
}
}
This is literally the only time in any of my script files that the PlayOneShot() function is called. There is absolutely no other reference to sounds or anything related at all anywhere else. This is completely beyond me and I think it is probably a Unity bug, so below is a link to my project files.
Thanks a lot for your help!
https://ufile.io/ucu4d (31.8MB)