Fire rate script? or is my unity broke?

Hi, I’ve tried several methods for Rate-Of-Fire in unity and nothing works. GameObjects are just con tinuesly spawned with no delay in all the methods i have looked up and tried, how do you do Rate of Fire C#? starting to think theirs somthing wrong in my version of unity, have googled and looked up on youtube for the last 3 days with no sucsess.

Can you post the script you're using?

Keep reducing it to simpler steps (and stop using UTube for non-cat stuff!!) Instead of "rate of fire" look for adding a delay, or waiting one second. There are answered Qs here about shooting (and jumping -- the lockout until you can jump again is the same idea) -- some of this answers won't help, but some will.

1 Answer

1

There are several ways of doing this, for example you could do something like this (not tested):

public class Weapon : MonoBehaviour {

   public float delay = 2.0f;
   private bool readyToFire = true;

   void Update(){
      if (Input.GetMouseButtonDown(0) && readyToFire){
         StartCoroutine(Fire());
      }
   }

   IEnumerator Fire(){
      readyToFire = false;
      // TODO -- add code to instantiate the projectile here.

      yield return new WaitForSeconds(delay);
      readyToFire = true;
   }
}

Might not be exactly what you need but should work in most cases, if you need more specifics feel free to provide any scripts you currently have or more info. Other examples of how to do it can be found here an answers as well.

Finally, here is some info about Coroutines if you have any questions: Unity - Scripting API: Coroutine

@GrimeBrett you shold start a new question as this is no more related. Briefly, I would create one build that contains no music, only logic. The music is stored on a server. On start, the user provides a url where the music is stored and it downloads it. End of it. You have on build for all students, but all students have different music downloaded. RESTful API is the concept.