Loot System

I am making a loot system that sends an icon from the loot generation script to the loot script attached to an enemy, the icon is then supposed to appear on the loot screen when the enemy has been killed.

The problem is that the icon is not appearing.

What am I doing wrong here?

LootGenerate.js:

var itemList1 : GameObject[];       //List of items to choose from (there will only ever be 2 items to choose from)
var itemList : GameObject[];      //List of items to choose from for the second item listed

function Loot1 () {      //This function is called when the enemy dies

for (var item1 : GameObject in itemList1) {      //A random item in the first list

   var icon1 = item1.GetComponent(Texture);      //The items icon element
   
   SendMessage ("FirstItem", icon1);      //The icon is sent over to the loot script

}

}

function Loot () {      //This function is also called when the enemy dies

for (var item : GameObject in itemList) {      //A random item in the second list for the second item on the loot screen

   var icon = item.GetComponent(Texture);      //The items icon texture
   
   SendMessage ("SecondItem", icon);      //The second icon is sent over to the loot script

}

}

You should post also the receiving script. Pretty hard to tell what is causing this to malfunction when we don’t see script that you send the information to :wink:

ReceivingScript.js:

var GUIEnabled : boolean = false;
var canLoot1 : boolean = true;
var canLoot : boolean = true;

var copper : int;
var silver : int;
var gold : int;

function Start () {

   silver = copper * 100;
   gold = silver * 100;

}

function OnGUI () {

   SendMessage ("Loot1");
   SendMessage ("Loot");

if (GUIEnabled == true) {

   var LootBackGround : Texture;

   GUI.Box( Rect( 300, 0, 150, 200), LootBackGround);
   
   
if (canLoot1 == true) {

   var redThing : Texture;

if (GUI.Button( Rect( 300, 0, 50, 50), redThing)) {

   canLoot1 = false;
	   		   	
}

}


if (canLoot == true) {

   var blackThing : Texture;
   
if (GUI.Button( Rect( 350, 0, 50, 50), blackThing)) {
   
   canLoot = false;
      
}

}


if (canLoot1 == false && canLoot == false) {

   BroadcastMessage ("Deactivate", 0.3);

   GUIEnabled = false;
   
}

}

}

function GUIActivate () {

   GUIEnabled = true;

}

function GUIDeactivate () {

   GUIEnabled = false;

}

function FirstItem (RedThing : Texture) {

   redThing = RedThing;

}

function SecondItem (BlackThing : Texture) {

   blackThing = BlackThing;

}

Ok… it may have taken me an age, but here it is. And it works too!

LootGenerate.js:

var icon1 : Texture;
var icon2 : Texture;

function Loot1 () {
   
   SendMessage ("FirstItem", icon1);

}

function Loot2 () {

   SendMessage ("SecondItem", icon2);

}

It’s for anyone else wants to send Texture information.