|
So I've taken some parts from the FPS tutorial script and chopped them up for my use. I'm right now only testing a sniper, and it will kill the "monster" i have, it shoots as fast as a machine gun, I dont know whats going on, everything here seems right:
I get no errors in the debug box and everything should work, but it still shoots like a machine gun. I cant figure it out, maybe you can
(comments are locked)
|
|
because you're calling "Reload()", and Reload() is a coroutine, your coroutine starts running separately to your main "Fire" function, and your "Fire" function is free to continue executing at full speed. If you want your firing to repeat, with a certain delay between every shot, while the fire button is held down, you could use something like this:
Alternatively, you could use the more "traditional" approach instead of coroutines (which can sometimes be simpler to understand), where you measure the amount of time elapsed since the last shot yourself: Thanks that should work Duck, and sorry Sebas for not responding, i kinda forgot i had this question up haha
Apr 07 '10 at 08:33 PM
Adam Bruns
no worries, glad it got solved :)
Apr 07 '10 at 09:03 PM
Sebas
yeah, also what i forgot to say is that its called by another script and has a SendMessageUpwards("Fire") thingy on it. Dunno why i didnt post that in the question
Apr 07 '10 at 09:15 PM
Adam Bruns
(comments are locked)
|
|
Just a guess: You didn't post your Update() function or the function where you actually fire your weapon (where you call your Fire() function. By looking at the above code, could it be that you can even fire without any ammunition? Possibly add an if statement that you can only fire when a bullet is loaded. What you have up there is simply the WaitForSeconds() to reload. Your described behavior would result if you continuously fire your gun without ammunition and the reloading just happens without any consequence.
(comments are locked)
|
