Hello all,
I’m neck deep in adapting the finished Laser Defender game to give it my own personal feel, however I’ve hit an issue which the support documents can’t resolve for me.
Below is the code, the intended result from this is that the player ship will fire a standard “WaterFire” (WF) projectile if the given key press is made. There are bools in place however to first determine if the player has an upgrade active which changes the projectile to WF2 or WF3. Both these types of attack I wish to limit how often the projectile can be fired.
This is the purpose of the Time.time
check prior to the WF2 and WF3 fire attempts.
Observed Behavior
The conditions for the below examples are such that the method we are attempting to call’s bool is set to true and the other, false.
Where the WaterFire3 ()
method is called this works as intended. The player can mash the key and it only fires at the desired intervals.
However the WaterFire2 ()
method fires an initial shot, then any further attempts to fire will fail, unless the desired time interval has elapsed. This tells me that the timer is resetting at the key press, rather than waiting for the time to elapse before waiting for the key press.
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
if (waterUpgrade1) {
if (Time.time >= wlvl2timeStamp)
WaterFire2();
wlvl2timeStamp = Time.time + timebetweenwlvl2Shots;
} else if (waterUpgrade2) {
if (Time.time >= wlvl3timeStamp) {
WaterFire3();
wlvl3timeStamp = Time.time + timebetweenwlvl3Shots;
}
} else {
InvokeRepeating ("WaterFire",0.000001f,firingRate);
}
}
}
I have already tried declaring the time stamp and time between shots as separate values, originally there were a generic which was shared between the two WF methods.
I have also tried adding the Time.time check into the initial check to determine which method to call, e.g. as below.
if (waterUpgrade1 && Time.time >= wlvl2timeStamp)
Many thanks for any help you can offer.
Chris