Item Abilities are a special type of Ability which allow for interaction with the Items that the character has. While the Item Ability is a subclass of the Ability class it has some special properties to it:

  • Item abilities are added to a separate list compared to standard abilities within the Ultimate Character Locomotion.
  • By default, multiple item abilities can be active at the same type. This allows the Aim item ability to still be active while the Use item ability is active.
  • Item abilities do not use a priority system to determine which abilities can be active. They do use the priority system when determining which ability should set the animator parameter.

Item abilities have no restrictions in what they can or cannot do – for example they can still control the character’s rotation if required. New item abilities can be created with similar steps as the New Ability topic.

Inspected Fields

Item State Index

Specifies the index of the Item State parameter within the Animator. A value of -1 indicates that the parameter is not used for this ability.

Events

When the ability starts or stops the “OnCharacterItemAbilityActive” event will be sent from the built-in Event System. A corresponding Unity event will also be sent. The following example will subscribe to this event from a new component:

using UnityEngine;
using Opsive.UltimateCharacterController.Events;
using Opsive.UltimateCharacterController.Character.Abilities.Items;

public class MyObject : MonoBehaviour
{
    /// <summary>
    /// Initialize the default values.
    /// </summary>
    public void Awake()
    {
        EventHandler.RegisterEvent<ItemAbility, bool>(gameObject, "OnCharacterItemAbilityActive", OnItemAbilityActive);
    }

    /// <summary>
    /// The specified item ability has started or stopped.
    /// </summary>
    /// <param name="itemAbility">The item ability that has been started or stopped.</param>
    /// <param name="activated">Was the ability activated?</param>
    /// </summary>
    private void OnItemAbilityActive(ItemAbility itemAbility, bool activated)
    {
        Debug.Log(ability + " activated: " + activated);
    }

    /// <summary>
    /// The GameObject has been destroyed.
    /// </summary>
    public void OnDestroy()
    {
        EventHandler.UnregisterEvent<ItemAbility, bool>(gameObject, "OnCharacterItemAbilityActive", OnItemAbilityActive);
    }
}