My Possible Solution to Repeat Fire Bug

This essentially creates a timer for unity to ignore repeated button clicks for a set amount of time.

private float fireTimer = 0;

private void Update()
{
    fireTimer += Time.deltaTime;

    PlayerFire();
}

private void PlayerFire()
{

    if (Input.GetButtonDown("Fire1")&& !firing && fireTimer > 0.5)
    {

        StartCoroutine(FireContinuously());

        fireTimer = 0f;
    }
    if (Input.GetButtonUp("Fire1") && !Input.GetButton("Fire1"))
    {
        StopCoroutine(FireContinuously());
        firing = false;

    }
     

}

private IEnumerator FireContinuously()
{
    do
    {
        Vector2 laserStart = new Vector2(transform.position.x, transform.position.y + YPadding);
        GameObject laser = Instantiate(laserPrefab, laserStart, Quaternion.identity) as GameObject;
        laser.GetComponent<Rigidbody2D>().velocity = new Vector2(0, projectileSpeed);
        yield return new WaitForSeconds(projectileFiringPeriod);
    }
    while (Input.GetButton("Fire1"));

So while playing with the number it still doesn’t completely fix the issue the way that I would truly like but it is a workaround.

Privacy & Terms