Picking up an object

I am getting from what I can see a very bazar error telling me that AddToInventory has no receiver.

Sending the information script:

if (canLoot2 == true) {
   
if (GUI.Button( Rect( 280, 70, 50, 50), thing2Texture)) {

   Instantiate(thing2, transform.position, Quaternion.identity);
   
   thing2.SendMessage ("AddToInventory");
      
   canLoot2 = false;
      
}

}

AddToInventory function (belongs to the item):

function AddToInventory () {

   var inventory = player.GetComponent(Inventory);
   
if (inventory != null) {
      
   inventory.AddItem(this);  
      
   isTrigger = true;
   
   renderer.enabled = false;
   
   transform.position = inventory.transform.position;
   
}

}

thing2 is the name of the prefab, not the name of the Instantiated instance of the prefab.

Change the 2 lines in the original code to:

var aThing = Instantiate(thing2, transform.position, Quaternion.identity);
aThing.SendMessage (“AddToInventory”);

I think you want to change your instantiate and sendMessage lines to look something like this:

var newThing = Instantiate(thing2, transform.position, Quaternion.identity);
newThing.SendMessage("AddToInventory");

thing2 is a reference to the object to be instantiated, not the newly instantiated object… you need to store the new object in a variable (newThing in my example)