I have a bit of a problem playing the audio on a machine gun on Android. The code is from stock machine gun (for the audio part)
function LateUpdate() {
if (muzzleFlash) {
// We shot this frame, enable the muzzle flash
if (m_LastFrameShot == Time.frameCount) {
muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward);
muzzleFlash.enabled = true;
if (audio) {
if (!audio.isPlaying)
audio.Play();
audio.loop = true;
}
} else {
// We didn't, disable the muzzle flash
muzzleFlash.enabled = false;
enabled = false;
// Play sound
if (audio)
{
audio.loop = false;
}
}
}
}
And here’s the code for firing the weapon:
if (GUI.RepeatButton (new Rect (644, 373,107,107), "", fireStyle))
BroadcastMessage("Fire");
I attached an audio source to the weapon and set it to loop (disabling that option won’t work either).
I am thinking this must have something to do with the RepeatButton code, which I need since the player should keep the button pressed as long as it wants to fire as opposed to short bursts. Any ideas where I might be doing it wrong? Thanks!