Shots on loop

Hi guys,

I have this script attached to the boss, but it’s shooting only when I press mouse, and I would like to put it in the loop to shoot 2times per second, how could I do it?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class EnemiesShots : MonoBehaviour
{
    public float speed;

    public GameObject shot;
    public Transform shotSpawn;
    public float fireRate;
  
    private float nextFire;
 
    void Update ()
    {
        if (Input.GetButton("Fire1") && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
        }
    }

}

I found out, If I remove “Input.GetButton(“Fire1”) &&” it works :slight_smile:

1 Like