How to make a reloading time because now i can shoot unlimited

Hello,
I have a problem and i think is t not very hard but i can’t fix it. Now i can shoot rockets but there is no limit, i can shoot unlimited and that not really realistic :slight_smile:
thanks in advance,
Sander

Script:


using UnityEngine;
using System.Collections;

public class RocketSpawnSource : MonoBehaviour {
	public GameObject RocketPrefab;
	public static bool rocketShooted;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {

		if (Input.GetMouseButtonDown(0))

		{
			Instantiate(RocketPrefab,transform.position,transform.rotation);
			StartCoroutine("RocketShooted");

		}
	}
}

You need a cool down of some sort.

 using UnityEngine;
 using System.Collections;
 
 public class RocketSpawnSource : MonoBehaviour {
     public GameObject RocketPrefab;
     public static bool rocketShooted;
     public int RocketCoolDown = 5; // Used to assign in editor and reset the rocketCoolDownCount.
		 
     private int rocketCoolDownCount;
		 
     // Use this for initialization
     void Start () {
				rocketCoolDownCount = RocketCoolDown; // initialize the Cool down count.
     }
     
     // Update is called once per frame
     void Update () {
 
         if (Input.GetMouseButtonDown(0))
         {
		     if (rocketCoolDownCount > 0)
		     {
		     	rocketCoolDownCount--;
		     }
		     else
		     {
	     	    Instantiate(RocketPrefab,transform.position,transform.rotation);
		     	StartCoroutine("RocketShooted");
		     }
         }
     }
 }

In your RocketShooted method that you didn’t include here, you need to reset the rocketCoolDownCount to RocketCoolDown.

// in your RocketShooted method, after shooting
rocketCoolDownCount = RocketCoolDown;

float shootDelay = 0.2f;
float currentDelay;

void Start()
{
currentDelay = Time.time + shootDelay;
}

void Update () {
 
         if (Input.GetMouseButtonDown(0))
 
         {
           if(Time.time > currentDelay)
             {
             Instantiate(RocketPrefab,transform.position,transform.rotation);
             StartCoroutine("RocketShooted");
             currentDelay = Time.time + shootDelay;
             }
 
         }
     }