- Home /
Question by
AreebM · Sep 15, 2014 at 06:45 AM ·
updateframeratefixedupdateframes
Getting Input every few frames?
Hi,
Currently I'm using FixedUpdate to get touch input for a cannon in my game.Once the user touches the cannon, the bullet fires and depending on what it touches next, certain things happen with lives and scores.
The problem is that when I touch the cannon, the input is taken so many times (i.e. so many frames pass while I'm touching the screen for that brief instant) that multiple bullets are fired, collide with each other as they instantiate, and affect the score/lives in weird ways. Is there any way I can slow the Instantiation or get input every few frames?
Comment
Answer by Tornado92 · Sep 15, 2014 at 08:00 AM
Use a bool and a timer.
Something like this should work
bool canShoot;
float timer = 3; //However long you want it to be in seconds.
if(canShoot){
//Do your shooting scripting here
canShoot = false
}
if(!canShoot) {
timer -= time.deltaTime
if (timer < 0) {
canShoot = true;
}
}
That's how I usually do it