Quantcast
Channel: Answers for "Efficient AutoFire Burst Script Help"
Viewing all articles
Browse latest Browse all 4

Answer by Fattie

$
0
0
Don't use coroutines and yield at all, unless you are way way advanced. Just use invoke. A simply approach is to just order up the next bullet, after the end of the previous bullet. invoke shootOne 0.1 shootOne... if no ammo, reload actually fire the gun invoke shootOne 0.1 reload... actually reload the gun let's say that takes about 2 seconds invoke shootOne 2.05 make sense? It's just a case of K.I.S.S. Caveat: your "gunner" code is so incredibly advanced, I just do not understand it in the slightest. What are you trying to do in there, some sort of state machine that tracks shooting or something? It's beyond me, sorry. But you can do continuous gunfire like the above! PERFORMANCE: you mention performance. It's likely completely unrelated to the issues mentioned here. Are you repeatedly instantiating a bullet, perhaps? What you do is just make a stash of 100 of them offscreen, and use them cyclincally, usually. Hope it helps in some way ---- in general for any beginners reading (not you, voncarp); For any beginners reading: it's a great pity Unity mention coroutines and yield in the doc. There is no reason at all to use them other than for very advanced situations. Basic everyday video game programming is just long lists of "Invoke" commands. The "Invoke" command are built, technically, using Fancy Stuffs like coroutines and yield. This is precisely why they added "Invoke" ... it's the simple, everyday way to do stuff like this. For example, routine for a three shot burst .. _fire() Invoke("_fire", 0.1); Invoke("_fire", 0.2); ten shot burst ... type it out like that or use a loop. Starting sequence for a race game.. // let's say it is now 5 seconds before the race starts Invoke("setALlCarsFirstGear", 3.25); Invoke("blinkOneSecondLights", 4.0); Invoke("releaseBrakes", 4.0); Invoke("beginCrowdRoaringStuff", 3.25); Invoke("launchAICars", 1.055); Invoke("beginThreeSecondCountdownAudio", 2); Invoke("startRaceTimer", 5.0); ..and so on (you'd have dozens of those, to start a race in a real race game)

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>