How would go about making a weapon pick up?

Hi I'm making a first person shooter where the player can hold, use and switch between two weapons. I want to be able find a weapon on the ground, pick it up and switch it out with one of my weapons and drop that weapon and use the new weapon. I could really use some help on a semi easy way to do this.

What you could first do is create an array for the player's weapons (in a weapon control script similar to the one in the FPS Tutorial). That would allow you to have two easily switched out weapons and leave the option the increase the number of weapons easily. This script would manage the weapons as well as tell them when to fire/reload and would be added to the main camera of your player (the weapons themselves would be children of the main camera). The weapon scripts would have functions called "selectWeapon" and "deselectWeapon" to turn them on or off.

    var weapons : GameObject[]; 
var selectedWeapon : int;
function Start () {

// Select the first weapon
SelectWeapon(0);
}

function Update () {
if (Input.GetKeyDown("1") && !(weapons[0].gameObject.GetComponent("weaponlocking").isLocked)) {
    SelectWeapon(0);
    selectedWeapon = 0;
}   
else if (Input.GetKeyDown("2") && !(weapons[1].gameObject.GetComponent("weaponlocking").isLocked)) {
    SelectWeapon(1);
    selectedWeapon = 1;
}   
    if (Input.GetButtonDown("Reload"))
        BroadcastMessage("Reload");

}

function SelectWeapon (index : int) {
    for (var i : int=0 ;i<weapons.length; i++)  {
        //select the weapon
        if (i == index){
        weapons*.gameObject.BroadcastMessage("selectWeapon");*
 *// Deactivate all other weapons*
 *}else{*
 _weapons*.gameObject.BroadcastMessage("deselectWeapon");*_
 _*}*_
_*}*_
_*```*_
_*<p>What you could then do is create a "selectableWeapon" script, which would only need to have one variable (the weapon that it references). You would put this script on the weapon model in the environment and then tag it as something like "pickupAble" (so that when the player looked at the weapon lying on the ground they can pick it up).</p>*_
_*```*_
_*var weapon : GameObject;*_
_*```*_
_*<p>You would just need to have every possible weapon be attached to the main camera (all but two of them being deactivated), so that when the player selects a gun off the ground that weapon would activate one of the player's weapons. Here's a "selectweapon" script that you could put on the main camera to actually switch the weapons out.</p>*_
_*```*_
_*function Start (){*_
 _*//playerWeapons is the weapon controller script from above*_
 _*playerWeapons = this.GetComponent("playerweapons");*_
_*}*_
_*function Update () {*_
 _*//this draws a ray to check if the player is looking at a selectable weapon. It would also be possible to use OnMouseOver unless you have a texture in the middle of your screen (textures block OnMouseOver so if you have a crosshair you can't really use it)*_
_*ray = transform.camera.ScreenPointToRay (Vector3(Screen.width/2.0,Screen.height/2.0,0));*_
_*if(Physics.Raycast(ray,hit,100)) {*_
 _*if(hit.collider.gameObject.tag == "pickupAble") {*_
 _*selectedWeapon = hit.collider.gameObject;*_
 _*} else {*_
 _*selectedWeapon = null;*_
_*}*_
_*if(selectedWeapon && Input.GetButtonDown("pickup")){*_
 _*for (var i : int=0 ;i<playerWeapons.weapons.length; i++){*_
 <em>_if(playerWeapons.weapons *== selectedWeapon.GetComponent(SelectableWeapon).weapon)*_</em>
 <em>_*return;*_</em>
 <em>_*}*_</em>
 <em>_*playerWeapons.weapons[playerWeapons.selectedWeapon].gameObject.BroadcastMessage("deselectWeapon");*_</em>
 <em>_*playerWeapons.weapons[playerWeapons.selectedWeapon] = selectedWeapon.GetComponent(SelectableWeapon).weapon;*_</em>
 <em>_*playerWeapons.SelectWeapon(playerWeapons.selectedWeapon);*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*```*_</em>
<em>_*<p>These are trimmed down scripts from my game, so they would require some tweaking to work in another one. Again, though, a lot of this is derived from the <a href="http://unity3d.com/support/resources/tutorials/fpstutorial.html" rel="nofollow">FPS Tutorial</a> if you want to look at that. Also, sorry if this is too long or too specific.</p>*_</em>

Can u help me with the weapons pack from you? , its says that the Reload input and the pickup input is missing how do i add it?
i download your pack

link text Note i didnt add throwing but that can be done quite easily now its grabable. i was kinda saving that bit to last

Hey I have added 2 Script to Complete a full Grab toggle and ready to move code,

Fixed An Inversion Error and a Euler read error while moving. since yesterday it is now working as stated below

ObjectGrabIdAndLock, ObjectReplyIdAndMove

ObjectGrabIdAndLock goes on Main player,… ObjectReplyIdAndMove goes on Moveable Objects remember to add layers in you want to hit in inspector and pick the Headcam Ect

Updated Scripts Since the other week now with full movement And Rotation and Full Inversion Options

This is Complete bar Diagnals and Mouse Rotation as im adding this now, you want to use the option OverideDiagnals and possibly UseDefaultRotation if u hate my defualt.

too add mouse copy the whole auto inversion and paste it underneath and swap the names to the mouse names instead of the default keys its a mission dont attempt it lol. i will do this over the week as still cleaing up the script its pretty large, Please contact at Exvalid@gmail.com To give me job coding.

cheers Ryan kappeslink text Exvalid@gmail.com
[105519-objectgrabscripts.zip|105519]