Weapon swap and walking at the same time

I have one button for a weapon swap and I use Input.ResetInputAxes() to allow for Q to swap the weapon out multiple times with the same button. It works great except for whenever you are walking because you stop walking. ResetInputAxes resets all past button inputs and current inputs from what I have read in the Unity script reference. Any suggestions?

I’ve been messing with using if statements instead of ResetInputAxes but I still haven’t gotten it to work. I wasn’t sure if I could push the same button twice and get a different result or even a third time so that’s why I went with the ResetInputAxes. Should I forget about the ResetInputAxes and go with if statements or is there a way to make ResetInputAxes work only for the (reload) button?

Don’t reset the input axes. Just put a delay on the command

if(Buttonpress&Time.TimeSinceLevelLoad>=swapdelay)
{
  swapdelay = Time.TimeSinceLevelLoad+1F;
}

Problem solved.

the way I have it set up is if the button is pressed and weapon2selected == false then weapon1selected = true and weapon2selected = false, if button is pressed and weapon2selected == true then weapon1selected = false and weapon2selected = true. I added your code and tweeked a few things in the script and all I could get it to do is count, what is the +1F? To get rid of and error I had to detect the F

Sorry, that’s C#'s way of letting you know the number is a Floating point decimal.

1F = 1.0.

I am starting to notice that when I put pseudocode into the forums, you Javascript folks start getting errors because you all seem to like to copy/pasta first, figure out what it does later. =P

As for your boolean setup, I’m going to ask you a question. Do you think that’s a smart way of doing things?

Let’s say you’ve got 2 weapons, as you already do. If weapon1selected is true, is weapon2selected ever going to be false?

Now let’s say you want to add another weapon. Now you have to make a new variable called weapon3selected, and test for that? Also, is weapon3selected ever going to be true when weapon2selected is true as well?

If your answer to any of the three questions above is yes, I’ma smack you in the head.

Yes, it should work, but it’s an absolutely awful way of handling things… Unless you are intending to write code that is going to make you rewrite it every time you want to add a new weapon.

A better way of handling this, would be to set up an integer variable, called “weaponSelected”, and store the weapon number that is currently selected in there.

Even better, you can store the actual object for the weapon that’s selected, but if you are using Javascript, that’s going to be a pain in the ass… So my suggestion is either learn C# (it’s insanely easy), or go with the integer solution.

Also, my code isn’t useful out of the box. It’s pseudocode. You are going to have to modify it to actually use it.