I have a gun firing sound audio clip and I want this to be played repeatedly while the mouse left button is pressed, like a machine gun where there is automatic firing.
If I do something like:
void Update()
{
if (gunScript.gotGun)
{
var mouse = Mouse.current;
var gamepad = Gamepad.current;
if (mouse != null)
{
if (mouse.leftButton.isPressed)
{
gunFireSound.Play();
}
}
}
}
It plays extremely rapidly as that's how the code gets executed very fast. How do I add a small delay or is there a better way to achieve this?
I also thought of an alternative but it doesn't play it fast enough. (the alternative was an if statement to check if it is finished playing, and play it again)
Thanks in advance. :)