Weapon Pickup and change

I’m using the code below to “pick up” an object with in trigger. I’m using the SetActiveRecrusivily to activate and deactivate objects. But now, when my “Secondary” is activated after “pick up”, I cannot activate my primary when key (1) is down. Please help

var hasRocketLauncher = false; // tells if you have a rocket launcher
var hasMachineGun = false; // tells if you have a machine gun
var ammoClips = 1; // tells how many ammo clips you have
var rockets = 10; // tells how many rockets you have
var Primary : GameObject;
var Secondary : GameObject;

private var inTrigger = false;
private var object: Transform;

function OnTriggerEnter(other: Collider){
  inTrigger = true; // the player entered the trigger
  object = other.transform; // save the object transform
}

function OnTriggerExit(other: Collider){
  inTrigger = false; // the player left the trigger
}

function Update(){
  // if player inside trigger and F pressed:
  
  if (inTrigger && Input.GetKeyDown("f")){     
    switch(object.tag){
      case "MachineGun": 
        hasMachineGun = true; // enable switching to the machine gun
        Destroy(object.gameObject); // destroy the picked object
        Primary.SetActiveRecursively(false);
      Secondary.SetActiveRecursively(true);
      if(Input.GetKeyDown("1")){
      Primary.SetActiveRecursively(true);
      Secondary.SetActiveRecursively(false);
      }
        break;
  
      case "RocketLauncher":
        hasRocketLauncher = true; // enable switching to the rocket launcher
        Destroy(object.gameObject); // destroy the object
        break;
      case "AmmoClip":
        ammoClips++; // increment ammo clips
        Destroy(object.gameObject);
        break;
      case "Rocket":
        rockets++; // increment rockets
        Destroy(object.gameObject);
        break;
    }        
  }

You should not place the weapon switching code inside that if, as @ThermalFusion noticed - you should press F and 1 in the same frame!

Add a function to select the weapon (SelWeapon) and call it when the corresponding weapon is picked - this will implement automatic switching to the newly picked weapon (not always a good idea…). Place the code to check keys 1 and 2 after that if, and call SelWeapon according to the key pressed:

...
function Update(){
  // if player inside trigger and F pressed:

  if (inTrigger && Input.GetKeyDown("f")){     
    switch(object.tag){
      case "MachineGun": 
        hasMachineGun = true; // enable switching to the machine gun
        Destroy(object.gameObject); // destroy the picked object
        SelWeapon(1); // select primary weapon automatically
        break;
      case "RocketLauncher":
        hasRocketLauncher = true; // enable switching to the rocket launcher
        Destroy(object.gameObject); // destroy the object
        SelWeapon(2); // select secondary weapon automatically
        break;
      case "AmmoClip":
        ammoClips++; // increment ammo clips
        Destroy(object.gameObject);
        break;
      case "Rocket":
        rockets++; // increment rockets
        Destroy(object.gameObject);
        break;
    }        
  }
  // Code to switch weapons when 1 or 2 is pressed:
  // - key 1 selects primary weapon:
  if (Input.GetKeyDown("1")) SelWeapon(1);
  // - key 2 selects secondary weapon:
  if (Input.GetKeyDown("2")) SelWeapon(2);
}

// function used to select weapon: activates only the selected weapon and 
// deactivates all others; only activates a weapon if the player already has it

function SelWeapon(nWeapon){
  Primary.SetActiveRecursively(nWeapon == 1 && hasMachineGun);
  Secondary.SetActiveRecursively(nWeapon == 2 && hasRocketLauncher);
}

Either there’s a problem with the object being destroyed and thus setting isTrigger to false, which will make everything in update to not happen because of if (inTrigger && Input.GetKeyDown(“f”)).
if(Input.GetKeyDown(“1”)) is also nested inside the block above, which means you have to press both f and 1 at the same time.