How to change the bullet fire rate in C#?

I tried use “Invoke” to make it, but it will repeat shooting every frame. Not every fixed second.
I wants to make it shoot in every 0.5 second. So how can I realize it?

Thank you, I'll take a look into it, see if I can figure it out! btw do you think it could have anything to do with any parameter of the optimization or configuration tab? ( see picture )[79613-unityask.jpg|79613]

1 Answer

1

Loop through a couroutine, in the contents have it:

  1. Instantiate your bullet prefab
  2. Add force to shoot it away
yield return
    new WaitForSeconds(0,5f);
  1. Repeat

How you loop it is up to you, depends on how you want it to shoot and from where it will shoot

Can you show me how to write the program in no.3? I have never use "yield" and "waitForSeconds" before. and thank you for your fast replay.

I don't think it has to do with the player settings. I would rather assume that you have some code that only executes when the player is in the middle street and that uses a badly designed algorithm. Alternatively, it could be that in the middle lane, some code starts doing recursive stuf. If it's not that, there are millions of possible reasons, hence the need for the profiler. Do you get any errors while emulating it in the editor?