In previous article we “Shoot Laser” from our space ship.
At the time we can fire laser without any intervals. which is very easy for player and not appropriate. we need to write some code which will add time interval in laser shooting. Add new variable called _fireRate. assign some value to it like 0.2f or any vale which we like. Then add condition in update where we can check the fire rate.
Time.time gives us the time at the beginning of the frame in seconds since start of the application. so if time at beginning of the frame is 0, and _canfire is 0, then we can fire laser. after firing laser _canFire will become, 0+0.2 = 0.2 (0.2 is value of fireRate ). so when time goes beyond 0.2s then only we can fire second laser. like, at the time Time.time = 0.3, we fired 2nd laser, _canFire become 0.3+0.2 = 0.5. so we can fire third laser when time goes beyond 0.5s it goes same for next.
There are other ways to achieve this. we are using this as for beginner friendly.
Our next step in this prototype is to add enemy. see you in the next article.