I am having trouble adding a delay to my shooting script for an FPS I am making and need help. I have looked at many other forum posts and videos but none have given me the solution I require. On a side note, I have close to no experience with C# and only know some of the basic terms so you’ll need to explain everything to me so I can learn. Anyway, I had figured out a system with Coroutine and IEnumerater, but the problem was that because I was using void update (because I need the system to check to see if I am pressing the proper button to fire each frame and so on) at first it would work, it would fire one bullet, wait a few seconds (I had exaggerated it for testing) but then it would fire tons of bullets at once. I know why this is; because all of the time that I was holding down the mouse button to fire it was building up and so after they had all waited for the few seconds it was just firing, you get the idea. Anyway, I need a system that will allow there to be a delay between shots and let me edit the delay to fit my needs. Here is my script.
using UnityEngine;
using System.Collections;
public class FP_Shooting : MonoBehaviour {
public GameObject bullet_prefab;
float bulletSpeed = 100f;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update () {
if (Input.GetButton(“Fire1”))
{
Camera cam = Camera.main;
GameObject Bullet = (GameObject)Instantiate(bullet_prefab, cam.transform.position, cam.transform.rotation);
Bullet.GetComponent().AddForce(cam.transform.forward * bulletSpeed, ForceMode.Impulse);
}
}
}
Thanks!
P.S. Yes I did use/am using Quill18Creates’ FPS tutorial