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?
Answer by vittu1994 · May 28, 2016 at 08:28 AM
Loop through a couroutine, in the contents have it:
Instantiate your bullet prefab
Add force to shoot it away
yield return new WaitForSeconds(0,5f);
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.
Have you worked with couroutines before? Its similar to a function. You need to make a IEnumerator (like a function works):
IEnumerator yourCouroutine()
{
//your stuff
}
then call it from start():
StartCouroutine(yourCouroutine());
Your answer
Follow this Question
Related Questions
(SOLVED) Destroy(gameObject) doesn't destroy the gameObject, only disables behaviours. 0 Answers
Trying to Invoke method: Spawner.SpawnObject couldn't be called. 2 Answers
Invoke () Working like InvokeRepeating () 2 Answers
Constant fire at target 2 Answers
Simple timer using InvokeRepeating 2 Answers