Skip to main content

KeyItem

A class in Root.Township, Alta.Inventory.

A pickup that works as a key. While inside a lock it's held at the lock's position and facing, after the player's IK runs.

Constructors​

MemberWhat it is
KeyItem()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

2 private and internal fields
MemberWhat it is
private GameObject[] collidersToDisableObjects moved to the Hand Triggers layer by SetColliders(false) and back to Default with true.
private Vector3 tipOffsetBacking field for TipOffset, the key tip's local offset.

Properties​

MemberWhat it is
bool IsInsideLock { get; set; }Whether the key is in a lock. Set by the lock.
Vector3 LockPosition { get; set; }Where the key is held while in a lock.
Vector3 LookAtLock { get; set; }Direction the key faces while in a lock.
Vector3 TipOffset { get; }Local offset of the key's tip.

Methods​

MemberWhat it is
override bool AssessScore(Interactor interactor, out float score)Can't be grabbed while the component is disabled.
override void FinishInteraction(Interactor interactor)Lets go normally, but treats a key inside a lock as mid-interaction so it stays put.
void SetColliders(bool enabled)Moves the key's set colliders to the Default layer, or to Hand Triggers to turn their collisions off.
protected override void OnDisable()Stops following the holder's IK.
protected override void OnDrawGizmosSelected()Draws the key's tip in the editor.
protected override void OnEnable()Starts following the holder's IK when grabbed.
3 private and internal methods
MemberWhat it is
private void DeRegisterIK(Interactable interactable, Interactor interactor)Unhooks Reposition from the holding player's IK updates when the interaction ends.
private void RegisterIK(Interactable interactable, Interactor interactor)Hooks Reposition into the holding player's IK updates when a player starts holding the key.
private void Reposition()After IK runs, snaps the key to LockPosition facing LookAtLock while it's inside a lock.

Used in​

Members of other types that take, return or hold a KeyItem: