Hi CommUnity,
I want my weapon to shoot a sprite in a regular interval.
I know how to instantiate an object and so on, my problem is the interval: The weapon fires e.g. 10 Sprites per second. How can I script that a sprite is instantiated every 1/10 second? The only solution I can think of is to create a variable containing the time of the last shot which is persistent, so it won’t be destroyed and rebuilt every script call.
I could then subtract “currenttime - timeoflastshot” and if the result is equal to or bigger then 1/10 second, a new sprite is fired and “timeoflastshot” is set to the current time.
Would this make sense or are there better solutions? As unity provides easy abstractions for lots of common things in gamedev (like this problem?) there maybe exist a built-in method to do “method calling in a specific interval” or something like that?
If the solution I imagined is the best one you could think of, too, then how can I make such a variable which is persistent? Is a ‘var timeoflastshot : integer;’ at the beginning of the script enough?
Thx!
Thank you very much