Getting Input every few frames?


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?

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.

     //Do your shooting scripting here
     canShoot = false

if(!canShoot) {
    timer -= time.deltaTime
    if (timer < 0) {
        canShoot = true;

That’s how I usually do it

you can use InvokeRepeating()