Gun swap through pickup?

This is hard to explain but here we go. I have 2 guns parented to the main camera, the main camera is parented to an empty gameobject that holds the cameras animations. These 2 guns are on 2 separate fps controllers, I have then made a prefab of both of these plus one that doesn’t have any gun at all just the cameras animations.

With this is there any way to swap guns with one that is on the ground that when the player walks over swaps them round? This is the easiest way I can describe what I’m trying to achieve, anyone who can help I would be very grateful.

I have had the same question, and thankfully, @AldoNaletto had the answer for it.

Use this code by @AldoNaletto, First you need to have 2 weapons, primary and secondary. Tag the primary one “MachineGun” and the secondary “RocketLauncher”. After applying the code on your controller, put a check mark next to MachineGun. Now, put your secondary weapon on the floor as a gameobject and tag it “RocketLauncher”. Create any collider and re-size it to be big. Check the “Is trigger”. Then play your project, walk over your weapon on the floor, press “f”, and the magic should happen hopefully. Don’t forget to set your primary and secondary variables as your weapons in the inspector.

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")){     
      case "MachineGun": 
        hasMachineGun = true; // enable switching to the machine gun
        Destroy(object.gameObject); // destroy the picked object
        SelWeapon(1); // select primary weapon automatically
      case "RocketLauncher":
        hasRocketLauncher = true; // enable switching to the rocket launcher
        Destroy(object.gameObject); // destroy the object
        SelWeapon(2); // select secondary weapon automatically
      case "AmmoClip":
        ammoClips++; // increment ammo clips
      case "Rocket":
        rockets++; // increment rockets
  // 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);