I am having an issue with the equipment effect script that comes with brackey’s inventory. I applied this script to my weapon in the scene. When I equip it, the effect adds the damage, but when I unequip, it it does not remove the damage. When I drop the item from inventory, it removes the damage.
Here is the Equipment Effect Script
#pragma strict
//This script allows you to create equipment effects that will be called either OnEquip or WhileEquipped. This is usefull for magic effects and stat handling.
static var minAttack : int = 5;
static var maxAttack : int = 20;
@script AddComponentMenu ("Inventory/Items/Equipment Effect")
@script RequireComponent(Item)
private var effectActive = false;
function Update ()
{
if (effectActive == true)
{
//-----> THIS IS WHERE YOU INSERT CODE YOU WANT TO EXECUTE AS LONG AS THE ITEM IS EQUIPPED. <-----
}
}
function EquipmentEffectToggle (effectIs : boolean)
{
if (effectIs == true)
{
effectActive = true;
Debug.LogWarning("Remember to insert code for the EquipmentEffect script you have attached to " + transform.name + ".");
//-----> THIS IS WHERE YOU INSERT CODE YOU WANT TO EXECUTE JUST WHEN THE ITEM IS EQUIPPED. <-----
PlayerStats.minAttack += minAttack;
PlayerStats.maxAttack += maxAttack;
}
else
{
effectActive = false;
Debug.LogWarning("Item Unequipped");
//-----> THIS IS WHERE YOU INSERT CODE YOU WANT TO EXECUTE JUST WHEN THE ITEM IS UNEQUIPPED. <-----
PlayerStats.minAttack -= minAttack;
PlayerStats.maxAttack -= maxAttack;
}
}
Here is the part of the Character script that handles the equipping and equipping.
//Equip an item to a slot.
function EquipItem(i:Item,slot:int)
{
if(i.itemType == ArmorSlotName[slot]) //If the item can be equipped there:
{
if(CheckSlot(slot)) //If theres an item equipped to that slot we unequip it first:
{
UnequipItem(ArmorSlot[slot]);
ArmorSlot[slot]=null;
}
ArmorSlot[slot]=i; //When we find the slot we set it to the item.
gameObject.SendMessage ("PlayEquipSound", SendMessageOptions.DontRequireReceiver); //Play sound
//We tell the Item to handle EquipmentEffects (if any).
if (i.GetComponent(EquipmentEffect) != null)
{
equipmentEffectIs = true;
i.GetComponent(EquipmentEffect).EquipmentEffectToggle(equipmentEffectIs);
}
//If the item is also a weapon we call the PlaceWeapon function.
if (i.isAlsoWeapon == true)
{
if (i.equippedWeaponVersion != null)
{
PlaceWeapon(i);
}
else
{
Debug.LogError("Remember to assign the equip weapon variable!");
}
}
if (DebugMode)
{
Debug.Log(i.name + " has been equipped");
}
playersinv.RemoveItem(i.transform); //We remove the item from the inventory
}
}
//Unequip an item.
function UnequipItem(i:Item)
{
gameObject.SendMessage ("PlayPickUpSound", SendMessageOptions.DontRequireReceiver); //Play sound
//We tell the Item to disable EquipmentEffects (if any).
if (i.equipmentEffect != null)
{
equipmentEffectIs = false;
i.GetComponent(EquipmentEffect).EquipmentEffectToggle(equipmentEffectIs);
}