How does a simple inventory work?

I need a two slot inventory in my game but I’m not that sure about how I am supposed to do it. I basically have 2 empty variables named slot1 and slot2. The plan is that if you press E while you’re in the area of the gameObject (the area is just an invisible isTrigger sphere), it gets added to your inventory as slot1. But I am not that sure how I would make that adding work. Here is my script that I wrote (I haven’t made anything for slot2 yet on purpose):

var slot1 : Transform;
var slot2 : Transform;

function Update () {

}

function OnTriggerEnter (other : Collider) {
	if(other.gameObject.tag == "Enemy") { 
		slot1 = other.gameObject.Transform;
	}
}

function OnTriggerExit (other : Collider) {
	if (other.gameObject.transform == slot1) {
		slot1 = null;
	}
}

Please explain how your editing of my script works so i can improve my scripting in the future.

PS: Please write the script in javascript.

So for your gameobject that is the “weapon” you’ll want a script on there that has functions for dealing with firing input.

Then you should grab that script when you collide with the weapon using this Unity - Scripting API: GameObject.GetComponent

I would have your update check to see if you have this “weapon” and if it does then you allow the input check for firing that weapon and if it is down then you fire.