|
Hello, I'm making a 4 barrel shotgun turret, and basically all I want it to do is fire each barrel one second after one another. Well, when I say fire, I mean for a muzzle flash texture to appear infront of each barrel.
This is nearly working ... it fires all the barrels in the correct sequence, but how do I then repeat it again? So it goes from: Barrel 1 ... then 2 ... then 3 ... then 4, and then just stops, how do I keep looping? If someone could help me out with this, then I would much appreciate it. Thanks
(comments are locked)
|
|
Just modify your existing loop a little bit: can I ask what the % 4 does?
May 10 '11 at 08:22 PM
oliver-jones
This only seems to be firing barrels 1 and 3 in a loop?
May 10 '11 at 08:30 PM
oliver-jones
"%" is the Mod operator http://en.wikipedia.org/wiki/Modulo_operation It essentially gives you the remainder of division. It comes in handy when you want to constrain an integer between 1 and n - 1.
May 10 '11 at 08:34 PM
flaviusxvii
Its okay - fixed it (my bad) -- How would I go about having a WaitForSeconds after every 4 shots? So it fires 4 shots ever second, and then waits for 3 seconds and fires the 4 shots again?
May 10 '11 at 08:37 PM
oliver-jones
Well, the easy approach would be to just write 'BarrelFlash(); yield WaitForSeconds(0.3)' four times, but on the fourth time, do WaitForSeconds(3.0)' instead. It's a bit repetitive but for something like this it's not much longer than the alternatives.
May 10 '11 at 10:55 PM
superpig
(comments are locked)
|
|
you could make a prefab and just put a remove after say a 1/5 of a second and istatate it every second and make the prefab have a point light component. yes no?? Well either way ... I still need help coding for the flash to move every second corresponding to the barrel. Thanks anyway
May 10 '11 at 06:53 PM
oliver-jones
do you mean move forward with the barrle transform or timing wise
May 10 '11 at 07:04 PM
joseph b
The barrel does not need to move. I want to know how to 'turn on' the flash game object on barrel 1, then turn off .. and do the same for barrels 2,3 and 4
May 10 '11 at 07:12 PM
oliver-jones
I already have a GameObject of a muzzle flash infront of each barrel ... I just want to be able to turn one on after another.
May 10 '11 at 07:26 PM
oliver-jones
(comments are locked)
|
|
It would make more sense to have a barrel object that manages it's muzzle flash, relative to itself. Then attach 4 of these barrels to a "gun" or "barrel controller" or something with an appropriate name and function. Then have that piece fire them in sequence. Read up on Object Oriented Programming. It is often very beneficial to recognize the objects in your program and write the code to encapsulate the individual parts. That way you could easily add a 3 or 5 barreled gun with very little work.
(comments are locked)
|
