Comparing two GameObjects to pick up items

Im trying to create a script for my 2d game, while hovering over the item, select it so that it then can be used, i found some code over the internet which relates closely to picking up a weapon but im having trouble following it [how would you go about a weapon pick up][1]

if(selectedWeapon && Input.GetButtonDown("pickup")){
    for (var i : int=0 ;i<playerWeapons.weapons.length; i++){
        if(playerWeapons.weapons *== selectedWeapon.GetComponent(SelectableWeapon).weapon)*

return;
}
Im doing my work in c# rather than java script and when i try to type this code out i get an error at where it would say getComponent().weapon(becuase it would be impossible for the compiler to know that selectedweapon has a variable of type weapon :S?), from what i understand, the code essentially asks whether the two gameobjects are the same. So in that case do i have to compare it in this way, can i not just refer to the tag of the object. Or is it more a case that selectedWeapon (in my case selectedTool) will have to be a custom class of some sort
here is my code for. I’m literally a month in learning unity so this is pretty new, if there is any other way of doing this im open to any suggestions
using UnityEngine;
using System.Collections;

public class SelectTool : MonoBehaviour {

  • public Tools tools;*

  • public float startTime;*

  • public bool ScalpalSelected;*

  • public GameObject selectedTool;*

  • void Start()*

  • {*

  •  tools = this.GetComponent<Tools>(); //in order to use this tools muyst be attached to the game object*
    
  •  //this is essentially saying  with regards to this game object get the component named tools*
    
  • }*

  • void update()*

  • {*
    _ /*this script will be attached to the cursor_
    _ * essentially what could be done is to_
    _ *_
    _ *_
    _ *_
    _ *_
    _ */_

  • }*

  • void OnCollisionStay(Collision Other)*

  • {*

  •  startTime +=Time.deltaTime;*
    
  •  if(startTime >5f){*
    
  •  	if(Other.collider.tag==("Scalpal"))*
    
  •  	{*
    
  •  		selectedTool = Other.collider.gameObject;*
    
  •  		Debug.Log(selectedTool+" What in gods good name is:");*
    
  •  		//this essential creates a scalpal object out of selected tool*
    
  •  	}*
    
  •  	else {*
    
  •  		selectedTool=null;*
    
  •  	}*
    
  •  	if(selectedTool){*
    
  •  		for(int i=0;i<tools.utilities.Length;i++)*
    
  •  		{*
    

_ if(tools.utilities*==selectedTool.GetComponent(SelectableUtils).tool)_
_
return;_
_
} _
_
}*_

* ScalpalSelected=true;*
* renderer.material.color = Color.yellow; *
* }*
* }*
* void OncollisionStay(Collision other){*

* startTime = 0f;*
* }*

}

_*[1]: http://answers.unity3d.com/questions/13522/how-would-go-about-making-a-weapon-pick-up.html*_

If I understood your question and your problem is here:

if(selectedWeapon && Input.GetButtonDown("pickup")){
    for (var i : int=0 ;i<playerWeapons.weapons.length; i++){
        if(playerWeapons.weapons *== selectedWeapon.GetComponent(SelectableWeapon).weapon)*

return;
}
}
I guess you could do this:
if(selectedWeapon && Input.GetButtonDown(“pickup”)){
for (var i : int=0 ;i<playerWeapons.weapons.length; i++){
if(selectedWeapon.GetComponent(SelectableWeapon).weapon && playerWeapons.weapons == selectedWeapon.GetComponent(SelectableWeapon).weapon)
return;
}
}