activate the armor part when the object is equipped ? SOLVED

Discussions, Solutions & How To with Inventory
AsteroZoha
Posts: 5
Joined: 23 Jan 2013, 18:45

activate the armor part when the object is equipped ? SOLVED

Postby AsteroZoha » 23 Jan 2013, 18:56

Hello,

As the title says, I try to figure out how to perform some actions when a specific item is equipped on the character screen.

My goal is to activate a gameObject (a gun, a bag) on the character body (just customize it visually).

Actually, I have all the equipment attached to my skeletton, they are all waiting to be active when the player equip an item on the slot.

But I really have no idea how to connect my item script (who is performing the action when equipped) and the inventory script.


can anyone help me ? :oops:
Last edited by AsteroZoha on 26 Jan 2013, 11:13, edited 1 time in total.

User avatar
Adam
Site Admin
Posts: 106
Joined: 07 Aug 2009, 14:54
Location: London, UK
Contact:

Re: activate the armor part when the object is equipped ?

Postby Adam » 25 Jan 2013, 16:15

AsteroZoha:

You should be able to find the place to put your code in the main "Inventory Manager" script under a function called "Equip Item" (iirc) - and there are a couple of these, depending upon overload - where the actual equipping of the item is done. My recollection of this function is when you attempt to equip the item, the function tests the slot to see if it is correct, and if so equips the item. You could put your code here. If this doesn't make sense to your code, you could look at the events that call "Equip Item" by searching for when it is called, and you should see something like "success = EquipItem(someItemVariable)" and then an if (success) {DoSomething;}/i] and you could inject your code at this point, but you'd need to find all of the possibilities. There should be only a few.

To UN-equip it, you need to find the event that returns the item back to the bag. This is an AddItem call (iirc), but you should be able to find this by searching for "remove" or "unequip", as I have this commented. Again there will be code like [i]"success = AddItem(someItemVariable)"
and then an if (success) {DoSomething;} which is where you will need to inject your unequip code.

Let me know if this helps, or if you need more detail.

AsteroZoha
Posts: 5
Joined: 23 Jan 2013, 18:45

Re: activate the armor part when the object is equipped ?

Postby AsteroZoha » 25 Jan 2013, 16:35

Thanks for the informations, :)

I knew it was near the "equip" function, but about the success event I didn't noticed,

I'm gonna make few tests and I tell you if I've got another problems !
Last edited by AsteroZoha on 25 Jan 2013, 17:32, edited 1 time in total.

AsteroZoha
Posts: 5
Joined: 23 Jan 2013, 18:45

Re: activate the armor part when the object is equipped ?

Postby AsteroZoha » 25 Jan 2013, 17:14

I have found the event, but the success var appear to be a boolean , as you can see, I added 2 debug.Log to check if it's ok but they are called together at the same moment, so I'm not sure where I have to place them to detect when it's unequipped/equipped on the character screen... ?

Also, I try to get the name of the equipped item (the variable itemName I suppose) and send it to my personal script, but the Class structure confuse me (I tried something like : equipped[i].itemName or InventoryItem.itemName, but no results).



Image

AsteroZoha
Posts: 5
Joined: 23 Jan 2013, 18:45

Re: activate the armor part when the object is equipped ?

Postby AsteroZoha » 26 Jan 2013, 00:54

I finally found the right place on the script to resolve my problem, thanks again for your help ! This is much appreciated !

User avatar
Adam
Site Admin
Posts: 106
Joined: 07 Aug 2009, 14:54
Location: London, UK
Contact:

Re: activate the armor part when the object is equipped ? SO

Postby Adam » 28 Jan 2013, 13:33

Great! I'm glad it worked out for you!

Yes, the "success" is "boolean", but then you use the "success" (if true) to activate your armor, as it has been successfully equipped, but be aware that this manner of checking things was used in a few locations, so you do need to find the correct one!


Return to “Inventory (for Unity Gui)”

Who is online

Users browsing this forum: No registered users and 1 guest