Code not doing anything

Hello everybody, i modified a piece of code that i found for an inventory system, and after i changed it it doesn’t work anymore. The only piece of code that was modified was the following:

function OnCollisionStay(col : Collision){
	if(!collider.isTrigger){
		if (Input.GetButtonDown("TakeItem")){
		    var playersinv=FindObjectOfType(Inventory);
		    playersinv.AddItem(this.transform);
		    MoveMeToThePlayer(playersinv.transform);
	    }
    }
}

It should make it so that whenever i press E it picks up the item and puts it in my inventory but it does absolutely nothing. Does anybody know how to fix this? PS: i know that this is some very shoddy coding, still learning.

You need to add it with some form of update, that calls the script, such as function Update…

Try this :

var takeButtonPushed:boolean = false;

function Update () {
    if (Input.GetButtonDown("TakeItem")) takeButtonPushed = true;
    if (Input.GetButtonUp("TakeItem")) takeButtonPushed = false;
}

function OnCollisionStay(col : Collision){
    if(!collider.isTrigger){
       if (takeButtonPushed)){
           var playersinv=FindObjectOfType(Inventory);
           playersinv.AddItem(this.transform);
           MoveMeToThePlayer(playersinv.transform);
        }
    }
}

The boolean will take care of making the intel travel between the two methods.