using UnityEngine; public class InfiniteStairs : MonoBehaviour { [Header("Settings")] [Tooltip("How many times must they climb before the loop breaks?")] public int loopsRequired = 3; [Tooltip("Drag an empty GameObject here. Position it lower down the stairs.")] public Transform resetPoint; private int currentLoops = 0; void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { // Only loop if we haven't finished the required cycles if (currentLoops < loopsRequired) { // 1. Calculate the offset // This ensures if they enter the trigger on the left side, // they appear on the left side at the bottom (smooth transition) Vector3 offset = other.transform.position - transform.position; // 2. Teleport // We keep their Rotation exactly the same, only changing Position CharacterController cc = other.GetComponent(); // You must disable CC briefly to teleport, or it sometimes fights back if (cc != null) cc.enabled = false; other.transform.position = resetPoint.position + offset; if (cc != null) cc.enabled = true; // 3. Increment Loop currentLoops++; Debug.Log($"Stair Loop: {currentLoops} / {loopsRequired}"); } else { // Loop finished - Disable this trigger so they can pass Debug.Log("Loop broken. Player can proceed."); gameObject.SetActive(false); } } } }