x


OnTriggerEnter / Inventory question?!

I have an inventory array script written, and i would like to know if i can either add into that an "OnTriggerEnter" function or if not, how to write a script, so that whenever i enter a trigger that has the script attached to it, it will remove whatever amount of items happens to be in the inventory, and adds that same amount to its own counter, with a max of say 300, which then triggers a new scene. Is this possible? My inventory script is below:

enum InventoryItem{ DEBUG_ITEM, SCREW, NUT, BOSS_TRAY, BOSS_PLOWBLADE, BOSS_WINDBLADE, ENERGYPACK, REPAIRKIT, COUNT_NUM_ITEMS }

var PlayerInventory: int[] ;

var playerStatus: Player_Status; playerStatus = GetComponent(Player_Status) ;

//Item Properties----------------------------------------------

private var repairKitHealAmt = 5.0; private var energyPackHealAmt = 5.0;

//Initilaize Player's starting Inventory-------------------

function Start(){

PlayerInventory = new int[InventoryItem.COUNT_NUM_ITEMS];

for (var item in PlayerInventory){
    PlayerInventory[item] = 0;
}

//Give Player some starting items
PlayerInventory[InventoryItem.ENERGYPACK] = 1;
PlayerInventory[InventoryItem.REPAIRKIT] = 2;

}

//Inventory Management Functions----------------------------------

function GetItem(item: InventoryItem, amount: int){ PlayerInventory[item] += amount; }

function UseItem(item: InventoryItem, amount: int){

if(PlayerInventory[item] <= 0) return;

PlayerInventory[item] -= amount;

switch(item){
    case InventoryItem.ENERGYPACK:
       playerStatus.AddEnergy(energyPackHealAmt);
       break;
    case InventoryItem.REPAIRKIT:
       playerStatus.AddHealth(repairKitHealAmt);
       break;
}

}

function CompareItemCount(compItem: InventoryItem, compNumber: int){

return PlayerInventory[compItem] >= compNumber;

}

function GetItemCount(compItem: InventoryItem){ return PlayerInventory[compItem]; }

@script AddComponentMenu("Inventory/Player's Inventory")

more ▼

asked Nov 02 '11 at 01:32 AM

empire72 gravatar image

empire72
16 7 7 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You've got a couple options.

1) Create functions to count items and remove items from the player, then implement inventory on whatever will be holding the items.

2) Create functions to get and remove the entire inventory at once, and then implement inventory on whatever and have functions to set the whole inventory at once.

more ▼

answered Nov 02 '11 at 01:44 PM

wccrawford gravatar image

wccrawford
91 1 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3318
x334
x223
x91
x67

asked: Nov 02 '11 at 01:32 AM

Seen: 637 times

Last Updated: Nov 02 '11 at 01:44 PM