Skip to main content

ScrollWheel

A class in Root.Township, the global namespace.

A wheel the player spins by hand: it follows the hand around its axis, lets go if the hand moves too far off, and keeps spinning with drag after release. Runs locally on each client.

Constructors​

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

Fields​

12 private and internal fields
MemberWhat it is
private float angleFromUpToMiddleAngle from up around the axis to the middle of the grab area.
private float angularVelocityCurrent spin speed in degrees per second.
private float angularVelocityDragHow fast the free spin slows, in degrees per second squared.
private Transform cachedTransformCached own transform.
private Interactable dummyPickupThe interactable the player grabs to turn the wheel.
private UnityEvent finishedSpiningEvent fired when the free spin stops.
private Coroutine interactingCoroutineThe running hand-following coroutine.
private float maxAngleToReleaseDot product limit; when the hand is further from the grab area's middle than this, it's released.
private float maxAngularVelocityHighest spin speed kept on release. Default 100.
private FloatEvent rotatedAngleFloat event fired with each rotation step in degrees.
private Vector3 rotationAxisLocal axis the wheel turns around. Default forward.
private Coroutine spiningCoroutineThe running free spin coroutine.

Properties​

1 private and internal property
MemberWhat it is
private Vector3 RotationAxis { get; }The rotation axis in world space, using the parent's rotation.

Methods​

8 private and internal methods
MemberWhat it is
private void ApplyRotation(float angle)Turns the wheel by an angle around its axis and fires rotatedAngle with that angle.
private void Awake()Caches the transform and hooks the dummy pickup's interaction start and end.
private void CleanInteractingCoroutine()Stops the hand-following coroutine if running.
private void FinishedInteract(Interactable interactable, Interactor interactor)Stops following the hand and starts the free spin.
private IEnumerator Interacting(Interactor interactor) (iterator)Coroutine that turns the wheel with the hand each frame and force-releases a local hand that leaves the allowed area.
private void OnDrawGizmosSelected()Editor: draws the rotation axis.
private IEnumerator Spin() (iterator)Coroutine that keeps the wheel turning after release, slowed by angularVelocityDrag, then fires finishedSpining.
private void StartedInteract(Interactable interactable, Interactor interactor)Stops any spin and starts following the grabbing hand.