Double-tap Number keys

Hello am trying to make a fps game. and i try to set up my weapon system i havnt`s goten the script for changing weapons via scroll whell yett but am currious how i can get (Double-tap) effect eks
pressing (1) i have a knife but if i press 1 2 times quickly i get another kinife/weapon so instead of be limited to 0-9 i can have 0-9 *2 of weapons :slight_smile:
ps am Norwegian with Dyselexia and am New to UnityAnswer.etc so.

I didn’t test this but this should give you the idea.

  1. if a weapons key was pressed, store which key it was into lastPressedNumber

  2. if a weapons key was pressed, store the time when it happened to lastPressedTime

  3. (otherwise reset both lastPressedNumber and lastPressedTime)

  4. if a weapons key is pressed and the same key was pressed within doubleTapTime seconds, switch to secondary weapon of that key

    var lastPressedNumber : String;
    var lastPressedTime : Number;
    var doubleTapTime : Number = 0.3;
    function Update ()
    {
    //Check if the fire button was pressed
    if(Input.GetButton(“Fire1”))
    BroadcastMessage(“Fire”);

     var timeSincePress: Number = Time.realtimeSinceStartup - lastPressedTime; 
     if(Input.GetKeyDown("1"))
     {
     	if (timeSincePress < doubleTapTime && lastPressedNumber == "1")
     	{
     		SelectWeapon(10);
     	}
     	else
     	{
        	SelectWeapon(0);
     	}
     	lastPressedNumber = "1";
     }
     else if(Input.GetKeyDown("2"))
     {
        if (timeSincePress < doubleTapTime && lastPressedNumber == "2")
     	{
     		SelectWeapon(11);
     	}
     	else
     	{
        	SelectWeapon(1);
     	}
     	lastPressedNumber = "2";
     }
     else if(Input.GetKeyDown("3"))
     {
        if (timeSincePress < doubleTapTime && lastPressedNumber == "3")
     	{
     		SelectWeapon(12);
     	}
     	else
     	{
        	SelectWeapon(2);
     	}
     	lastPressedNumber = "3";
     }
     else if(Input.GetKeyDown("4"))
     {
         if (timeSincePress < doubleTapTime && lastPressedNumber == "4")
     	{
     		SelectWeapon(13);
     	}
     	else
     	{
        	SelectWeapon(3);
     	}
     	lastPressedNumber = "4";
     }
     else
     {
     	lastPressedNumber = null;
     	lastPressedTime = 0;
     }
     
     if (lastPressedNumber != null)
     {
     	// something was pressed
     	lastPressedTime = Time.realtimeSinceStartup;
     }
    

    }