using UnityEngine; public class EndlessDescenderController : MonoBehaviour, ITouchInputConsumer { private float targetFingerX; private bool isTouchActive; private float originY; void Awake() { originY = transform.position.y; } void Start() { // Register as default consumer for input InputManager.Instance?.SetDefaultConsumer(this); // Initialize target to current position targetFingerX = transform.position.x; isTouchActive = false; } // Implement new ITouchInputConsumer contract public void OnTap(Vector2 worldPosition) { // Treat tap as a quick move to the tapped X position targetFingerX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax); isTouchActive = true; } public void OnDragStart(Vector2 position) { // } public void OnDrag(Vector2 position) { // } public void OnDragEnd(Vector2 position) { // } public void OnHoldStart(Vector2 worldPosition) { // Start hold, update target X targetFingerX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax); isTouchActive = true; } public void OnHold(Vector2 worldPosition) { // Update target x as finger moves targetFingerX = Mathf.Clamp(worldPosition.x, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax); } public void OnHoldEnd(Vector2 worldPosition) { // Stop hold isTouchActive = false; } void Update() { if (!isTouchActive) return; float currentX = transform.position.x; float lerpSpeed = GameManager.Instance.EndlessDescenderLerpSpeed; float maxOffset = GameManager.Instance.EndlessDescenderMaxOffset; float exponent = GameManager.Instance.EndlessDescenderSpeedExponent; float targetX = targetFingerX; float offset = targetX - currentX; offset = Mathf.Clamp(offset, -maxOffset, maxOffset); float absOffset = Mathf.Abs(offset); float t = Mathf.Pow(absOffset / maxOffset, exponent); // Non-linear drop-off float moveStep = Mathf.Sign(offset) * maxOffset * t * Time.deltaTime * lerpSpeed; // Prevent overshooting moveStep = Mathf.Clamp(moveStep, -absOffset, absOffset); float newX = currentX + moveStep; newX = Mathf.Clamp(newX, GameManager.Instance.EndlessDescenderClampXMin, GameManager.Instance.EndlessDescenderClampXMax); float newY = originY; // Add vertical offset from WobbleBehavior if present WobbleBehavior wobble = GetComponent(); if (wobble != null) { newY += wobble.VerticalOffset; } transform.position = new Vector3(newX, newY, transform.position.z); // Debug.Log($"EndlessDescenderController: Moved from {oldPos} to {transform.position} (targetX={targetX}, lerpSpeed={lerpSpeed}, offset={offset}, exponent={exponent}, moveStep={moveStep})"); } // Optionally, handle touch release if needed // You can add a method to reset isTouchActive if desired }