Skip to main content

CapPickup

A class in Root.Township, the global namespace.

The grabbable cap on a potion bottle. While the same player holds the bottle, pulling the cap far enough off removes the lid, which the server applies.

Constructors​

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

Fields​

6 private and internal fields
MemberWhat it is
private Pickup bottlePickupThe bottle this cap belongs to.
private AltaCoroutine checkingPopThe running CheckPop coroutine, if any.
private LiquidContainerLid lidThe bottle's LiquidContainerLid, removed when the cap pops.
private Vector3 popDirectionLocal direction the hand has to pull to pop the cap.
private float popDistanceHow far (0.1 by default) the hand has to pull along popDirection to pop the cap.
private MethodSync syncCapRemovedMethod sync that sends the cap removal from client to server.

Methods​

MemberWhat it is
override bool AssessScore(Interactor interactor, out float score)Only lets the cap be grabbed while its lid is on and the bottle is held by the same player. Gives it top priority when allowed.
override void Initialize()Creates the PotionCapRemoved method sync.
protected override void Awake()Hooks InteractionStarted to start checking for the pop.
protected override void OnDisable()Turns off the cap's colliders.
protected override void OnEnable()Turns the cap's colliders back on.
protected override void Start()Hooks the bottle's release and dock events.
6 private and internal methods
MemberWhat it is
private IEnumerator CheckPop() (iterator)Local coroutine: once the hand has moved popDistance along popDirection, lets go and tells the server the cap came off.
private void Release(Interactable interactable, Interactor interactor)Lets go of the cap when the bottle is let go.
private void ReleaseDocked(Interactor interactor, Pickup pickup, PickupDock dock)Lets go of the cap when the bottle is docked.
private void StartCheck(Interactable interactable, Interactor interactor)Restarts the pop check coroutine when the local player grabs the cap.
private void SyncCapRemoved(IPlayer player, Stream stream)Server: removes the lid when the message comes from the player who last held the cap.
private void ToggleColliders(bool isEnabled)Turns all the cap's colliders on or off.