|
I am trying to limit the rate of fire for my gun. I use this script: But whenever I try to put a WaitForSeconds, it says that function Update() cannot be a coroutine. How can I fix this.
(comments are locked)
|
|
You can use a boolean to prevent fire and set it outside of Update in a coroutine. use this outside of Update Assets/Player/machinegun.js(16,41): BCE0005: Unknown identifier: 'gunFired'.
May 27 '11 at 08:07 AM
Max 4
var gunFired : bool = false; use this on top of your code as a field.
May 27 '11 at 08:16 AM
homeros
Where do I put the first part? It doesn't seem to work.
May 27 '11 at 08:22 AM
Max 4
I don't exactly know which one you meant by first part but i'll list everything. -put "var gunFired : bool = false;" on top of your code, outside of every function. -replace "if(Input.GetButton("Fire1"))" with "if(Input.GetButton("Fire1") && !gunFired)" -put "StartCoroutine(GunFire());" on the first line inside if statement -put function GunFire() { gunFired = true; yield WaitForSeconds(1); gunFired = false; } anywhere outside of Update function.
May 27 '11 at 08:27 AM
homeros
Thanks mate, works like a charm. It was more complicated than anything I could have figured out.
May 27 '11 at 08:44 AM
Max 4
(comments are locked)
|
