Yes, that would be the route. You can create a new item ability that calls StartEquipUnequip. Take a look at this page for an example: https://opsive.com/support/documentation/ultimate-character-controller/items-inventory/inventory/An item ability maybe?
GetActiveCharacterItem returns the current item that is equipped, not necessarily used. You can subscribe to the OnUseAbilityUsedItem event to get the last used item: https://opsive.com/support/document...ller/programming-concepts/events/event-names/Also, would `GetActiveCharacterItem(slotID)` return the last used weapon, or would I need to keep track of that in a script variable?
/// <summary>
/// Used to keep track of items equipped
/// </summary>
/// <param name="equipItem">The item being equipped</param>
/// <param name="slotID">The slot the item is being equipped to</param>
private void AbilityWillEquipItem(CharacterItem equipItem, int slotID)
{
int itemSetIndex = m_EquipUnequipAbility.ActiveItemSetIndex;
if (itemSetIndex != -1)
m_CurrentItemSetIndex = itemSetIndex;
//Debug.LogFormat("AbilityWillEquipItem: {0}, slot: {1}, ActiveItemSetIndex: {2}, m_CurrentItemSetIndex: {3}", equipItem.name, slotID, m_EquipUnequipAbility.ActiveItemSetIndex, m_CurrentItemSetIndex);
}
namespace Opsive.UltimateCharacterController.Character.Abilities.Items
{
using Opsive.UltimateCharacterController.Utility;
/// <summary>
/// The EquipOnAttack ability will equip the current (last equipped) ItemSet automatically when the player attacks.
/// EquipOnAttack just specifies which ItemSet should be equipped and then will let the EquipUnequip ability to do the actual equip.
/// </summary>
[DefaultStartType(AbilityStartType.ButtonDown)]
[DefaultInputName("Attack")]
[AllowDuplicateTypes]
public class EquipOnAttack : EquipSwitcher
{
private int m_PrevItemSetIndex = -1;
/// <summary>
/// The EquipUnequip ability has changed the active ItemSet. Store this value so EquipOnAttack knows which ItemSet to equip after the unequip.
/// </summary>
/// <param name="itemSetIndex">The updated active ItemSet index value.</param>
protected override void OnItemSetIndexChange(int itemSetIndex)
{
if (!Enabled)
{
return;
}
if (itemSetIndex == -1)
itemSetIndex = 1; // player can't drop or change first item, so default to this
m_PrevItemSetIndex = itemSetIndex;
}
/// <summary>
/// The ability has started.
/// </summary>
protected override void AbilityStarted()
{
base.AbilityStarted();
// Start the EquipUnequip ability and then stop the ability. The EquipUnequip ability will do the actual work of equipping or unequipping the items.
m_EquipUnequipItemAbility.StartEquipUnequip(m_PrevItemSetIndex, false, false);
StopAbility();
}
}
}
Thanks! I will do that.Just search through some of the code for example usage. "OnDeath" maybe a good one to search for to kick off.